RootViewController动画过渡,初始方向错误 [英] RootViewController animation transition, initial orientation is wrong
问题描述
所以我按照这个主题: RootViewController切换过渡动画来传递window.rootViewController A到B到C.代码如下所示:
So I followed this thread: RootViewController Switch Transition Animation to transit the window.rootViewController from A to B to C. Code looks like this:
[UIView transitionWithView:self.window
duration:0.5
options: UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
self.window.rootViewController = newViewController;
}
completion:nil];
问题是我的应用程序只支持格局,但在rootViewController过渡期间,会出现新的视图控制器在纵向模式下比快速旋转到横向模式。
The problem is my app shall only support landscape, but during the rootViewController transition, the new view controller appears in portrait mode than quickly rotate to landscape mode.
我确定:
- 我为每个viewcontroller设置了UISupportedOrientation为横向(主页按钮右侧)
- ,在shouldAutoRotateToOrientation方法中,我只设置为横向
可能是另一个原因?
推荐答案
我调查了这个现在,因为我一直在遇到同样的问题。我随机尝试了以下内容,它运行得很好:
I looked into this just now because I kept getting the same issue. I randomly tried the following, and it worked perfectly:
[UIView
transitionWithView:window
duration:0.5
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^(void) {
BOOL oldState = [UIView areAnimationsEnabled];
[UIView setAnimationsEnabled:NO];
[(ICApp *)sharedApplication.delegate window].rootViewController = self;
[UIView setAnimationsEnabled:oldState];
}
completion:nil];
我知道在动画块中禁用/启用动画有点奇怪,但交叉消解动画,旋转没有 - 视图控制器似乎已经旋转并准备好滚动。
I know it's a bit odd to disable/enable animations inside an animation block, but the cross dissolve animates, and the rotation does not -- the view controller appears already rotated and ready to roll.
这篇关于RootViewController动画过渡,初始方向错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!