有一个视图控制器(让我们将其命名为parent),它使用presentModalViewController:animated:来呈现其他视图控制器(让我们将其命名为模态),然后旋转设备.两个控制器都支持所有方向.这里发生了什么:
>旋转后,模态控制器接收didRotateFromInterfaceOrientation:
>在解除模态控制器之前,父控制器也接收didRotateFromInterfaceOrientation:但是,仅当基本SDK设置为4.3(或更低)时才会发生.如果将基本SDK设置为5,则父控制器不会收到此消息.在4.3中,我根据didRotateFromInterfaceOrientation:中的新方向更新了父接口,并且在隐藏模态控制器后显示正确,但是在iOS 5中,它没有被调用,并且在隐藏模态控制器后父接口被搞砸了.
那么,如果在模态控制器可见时旋转设备,我该怎么做才能正确地将父控制器的界面更新为新的方向?
解决方法
我遇到过类似的问题.我的解决方案是将我的方向处理代码移动到一个单独的方法中,并从旋转方法和viewWillAppear调用:
//.h @interface SomeViewController - (void)layoutForInterfaceOrientation:(UIInterfaceOrientation)orientation; @end //.m @implementation SomeViewController - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; UIInterfaceOrientation currentOrientation = [[UIApplication sharedApplication] statusBarOrientation]; [self layoutForInterfaceOrientation:currentOrientation]; } - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toOrientation duration:(NSTimeInterval)duration { [self layoutForInterfaceOrientation:toOrientation]; } - (void)layoutForInterfaceOrientation:(UIInterfaceOrientation)orientation { // layout views } @end