在从模态视图返回后,iOS5不会调用willRotateToInterfaceOrientation:duration:。

3
我的主UIViewController重写了willRotateToInterfaceOrientation:duration:以适应正确方向的背景视图。当停留在视图中时,这个功能正常工作。
但是,在我的应用中,一些用户操作的结果可能会导致呈现另一个“女儿”UIViewController。当用户完成该女儿UIViewController后,通常会返回到主视图控制器。我的代码调用dismissModalViewControllerAnimated:来完成此操作。
当用户在女儿UIViewController在屏幕上时更改iPad方向时,问题就会发生。然后,主UIViewController将永远不会看到任何调用willRotateToInterfaceOrientation:duration:,并且其背景视图将不正确。
在iOS 4中,这种设置运行良好: iOS 4的dismissModalViewControllerAnimated:实现调用UIWindow_setRotatableClient:toOrientation:updateStatusBar:duration:force:,它为切换的UIViewController调用willRotateToInterfaceOrientation:duration:
显然,在iOS 5中,这种行为发生了变化。
在iOS5下,当我的视图处于离线状态时,我应该如何实现方向更改呢?例如,我应该在viewWillAppear:中查询当前方向吗?我这样做了,它很好地解决了这个问题,但我可能错过了什么。
1个回答

2
尝试通过通知中心处理接口变更,像这样:
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(orientationChanged:)
                                             name:UIDeviceOrientationDidChangeNotification 
                                           object:nil];

在"orientationChanged"方法中进行与界面相关的操作。

好的提示。我花了一个小时才弄清楚为什么willRotateToInterfaceOrientation:duration在iOS5中不起作用,但在iOS6中可以。 - TK189
如果在旋转发生之前需要完成某些事情,这并没有帮助到我们。 - some_id

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接