【发布时间】:2015-07-01 12:02:21
【问题描述】:
调用presentViewController:animated:completion: 在iOS7 中没有动画。视图立即出现。动画在 iOS8 中正常工作。当前方法在我的应用程序中的三个不同位置调用,它们都显示此行为。它发生在设备和模拟器上。
随后对 dismissViewControllerAnimated:completion: 的调用在所有 iOS 版本中都可以正确设置动画。
代码结构
调用本方法的视图控制器是UINavigationController的根视图控制器,而这个导航控制器是UITabBarController中的viewControllers之一。
每个呼叫都很简单,只需按一下按钮即可触发。这是其中一种情况:
GenreViewController *controller = [[GenreViewController alloc] init];
[self presentViewController:controller animated:YES completion:nil];
尝试修复
- 显式分派到主线程
- 演示前致电
[UIView setAnimationsEnabled:YES] - 为显示控制器添加延迟(只是为了看看会发生什么)
在每种情况下,行为都没有改变。
任何帮助将不胜感激!
更新 - 修复
原来UITabBarController 的modalPresentationStyle 属性被设置为UIModalPresentationCurrentContext。这在 iOS7 中不会动画,您必须改用 UIModalPresentationFullScreen 的演示样式。
【问题讨论】:
-
您是否覆盖了 GenreViewController 的 init 方法?也许你应该试试 GenreViewController *vc = [[GenreViewController alloc] initWithNibName:NSStringFromClass([GenreViewController class]) bundle:nil];
-
@Doro 我尝试了 initWithNibName:bundle: (并确保我的超类也都调用了它),但演示文稿仍然没有动画。
标签: ios objective-c iphone animation presentviewcontroller