View 关于shouldAutorotateToInterfaceOrientation方法

View 关于shouldAutorotateToInterfaceOrientation方法,view,View,我正在开发一个应用程序,其中使用了一些ViewController。当我在横向/纵向模式下从一个视图推到另一个视图并在相同模式下向后移动时,shouldAutorotateToInterfaceOrientation方法调用了move back 但当重复相同的步骤并且在第二个或第三个视图上更改方向并向后移动时,则不应调用AutoRotateTointerFaceOrientation方法。视图控制被干扰了 请给我一个固溶体 谢谢,如果我正确理解了您的问题,您希望在设备方向更改时,在viewCon

我正在开发一个应用程序,其中使用了一些ViewController。当我在横向/纵向模式下从一个视图推到另一个视图并在相同模式下向后移动时,shouldAutorotateToInterfaceOrientation方法调用了move back

但当重复相同的步骤并且在第二个或第三个视图上更改方向并向后移动时,则不应调用AutoRotateTointerFaceOrientation方法。视图控制被干扰了

请给我一个固溶体


谢谢,

如果我正确理解了您的问题,您希望在设备方向更改时,在viewController堆栈上的第二个或第三个viewController上调用shouldAutorotateToInterfaceOrientation

shouldAutorotateToInterfaceOrientation仅在top viewController上调用。如果在第二个或第三个viewController的方法中执行任何布局代码,则不会执行该代码

根据您的代码,解决方案既简单又多。这里有一个应该可以工作(没有在Xcode中测试)。在top ViewController的shouldAutorotateToInterfaceOrientation方法中,添加如下内容:

for (UIViewController *vc in [self childViewControllers])
{ 
    [vc shouldAutorotateToInterfaceOrientation];
}
如果您有一个指向特定childViewController的指针,则可以专门调用它

文件说明:

此方法的实现只需根据interfaceOrientation参数中的值返回YES或NO。不要试图获取interfaceOrientation属性的值或检查UIDevice类报告的方向值。视图控制器要么能够支持给定的方向,要么不能

要进行任何布局,可以使用:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
希望这有帮助