由于某种原因,我无法为两个子视图位置设置两个动画。我写了以下

[self addChildViewController:self.photosViewController];
[self.photosViewController.view setFrame:CGRectMake(0, -self.view.frame.size.height,    self.view.frame.size.width, self.view.frame.size.height)];

[self.view addSubview:self.photosViewController.view];

[UIView animateWithDuration:1 delay:0
                        options:UIViewAnimationOptionCurveEaseIn
                     animations:^{

                         [self.stepsView setFrame:CGRectMake(0, self.view.frame.size.height, self.view.frame.size.width, self.view.frame.size.height)];
                         [self.photosViewController.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
                     }
                     completion:^(BOOL finished) {
                         if (finished) {

                             button.tag = 0;
                         }
                     }];
self.stepsViewIBOutlet UIView,而self.photosViewController.view是已添加到视图的子视图控制器视图。

使用当前代码,只有self.PhotosViewController.view会动画。但是,如果我注释掉添加子视图控制器视图的行作为subview,则self.stepsView会正确设置动画。

即使我在调用此方法之前添加了子视图控制器及其视图,也会发生相同的错误。

我需要帮助,因为我几个月前用另一个应用程序遇到了这个问题,不得不做一个肮脏的破解来解决它,现在想解决这个问题。

谢谢

最佳答案

View Programming Guide中的视图动画部分中,有一个如何为子视图设置动画的specific mention

基本上,您应该使用transitionWithView:duration:options:animations:completion:而不是animateWithDuration:delay:options:animations:completion:

10-08 03:18