用动画交换 rootViewController [英] Swapping rootViewController with animation
问题描述
我在用动画交换 rootViewController 时遇到了一些麻烦.这是我正在使用的代码:
I'm having a little trouble swapping rootViewControllers with animation. Here's the code that I'm using:
[UIView transitionWithView:self.window duration:0.8 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{
self.window.rootViewController = self.navigationController;
} completion:nil];
它有点工作,只是在动画之前,屏幕变成黑色,然后动画发生.看起来原来的 rootViewController 在动画之前被删除了.有什么想法吗?
It kind of works except that right before the animation, the screen turns to black and then the animation occurs. It looks like the original rootViewController is getting removed right before the animation. Any ideas?
推荐答案
transitionWithView
旨在为指定容器视图的子视图设置动画.改变根视图控制器的动画并不是那么简单.我花了很长时间试图做到没有副作用.见:
transitionWithView
is intended to animate subviews of the specified container view. It is not so simple to animate changing the root view controller. I've spent a long time trying to do it w/o side effects. See:
动画变化不使用导航控制器堆栈、子视图或模态控制器的视图控制器?
添加了参考答案的摘录
[UIView transitionFromView:self.window.rootViewController.view
toView:viewController.view
duration:0.65f
options:transition
completion:^(BOOL finished){
self.window.rootViewController = viewController;
}];
这篇关于用动画交换 rootViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!