如果您的应用有一个 UIWindow
,我的理解是 UIWindow
的 rootViewController
将是 UIViewController
接收旋转/方向方法,如 shouldAutoRotate
、shouldAutoRotateToInterfaceOrientation
等。
我正在编写一个外部库,并且有一个实例,我在其中创建了另一个 UIWindow
对象,设置了它的 rootViewController
,并使其成为关键且可见。看起来原始窗口的 rootViewController
仍然是发送旋转方法的那个,而不是新的。
我希望能够控制应用程序是否可以在新窗口可见时旋转,但似乎原始窗口的 rootViewController
仍然可以控制它。我已经尝试将原始窗口的 rootViewController
设置为 rootViewController
,在我的新窗口可见时禁止旋转屏幕并重置原始窗口的 rootViewController
到它原来的 rootViewController
但这会导致它自己的一些问题。
有谁知道如何让某个 UIViewController
负责应用轮换?
最佳答案
您如何呈现新的 viewController?根据文档,唯一被询问 supportedInterfaceOrientations
的 viewControllers 是 Root View Controller ,或填充屏幕的 View Controller 。因此,在 iPhone 上,如果新的 viewController 正在填充屏幕(例如,以模态方式呈现),它应该会收到 supportedInterfaceOrientations
调用。
shouldAutoRotateToInterfaceOrientation
自 iOS 6 起已弃用,因此您应该改写 supportedInterfaceOrientations
。
关于ios - 多个 UIWindows 以及哪个控制状态栏方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19919174/