【发布时间】:2013-04-15 21:14:18
【问题描述】:
由于某种原因,我无法为两个子视图位置设置两个动画。我写了以下内容
[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.stepsView 是 IBOutlet UIView 和 self.photosViewController.view 是已添加到视图的子视图控制器视图。
使用当前代码,只有 self.PhotosViewController.view 动画。但是,如果我注释掉将子视图控制器视图添加为subview 的行,那么self.stepsView 的动画效果正确。
即使我在调用此方法之前添加子视图控制器及其视图,也会发生相同的错误。
几个月前我在使用另一个应用程序时遇到了这个问题并且不得不做一个肮脏的黑客来解决它,现在想要解决这个问题。
谢谢
【问题讨论】:
-
调用该动画块时 self.stepsView 是否非零?
-
你为什么同时调用 addChildViewController 和 addSubView?
-
@jsd 它在 IB 中,我从不将其从视图中删除,因此永远不会为零
-
@sixthcent 因为根据我对苹果文档和视频的理解,他们说应该始终将要添加为子视图的视图的视图控制器添加为视图控制器的子视图控制器也添加......如果这有意义的话。
-
我的评论是由您的声明提示的,如果您注释掉 addSubview 部分,则视图会动画。看起来你可能必须做两个单独的动画,一个接着一个。如果在第一个动画中隐藏stepsView,然后在completion handler中启动动画显示photosView,或许可以达到你想要的效果。
标签: ios xcode uiview uiviewcontroller core-animation