我需要在我的应用程序中支持所有界面方向掩码。 有些 View Controller 不应该自动旋转(它只支持纵向),但应用程序仍然需要支持所有方向。 Expected result
我尝试设置 shouldAutorotate = true; UINavigationController 中的 supportedInterfaceOrientations = All
和 shouldAutorotate = false; supportedInterfaceOrientations = Portrait
在 Root View Controller 中。但它不起作用。
最佳答案
您可以在仅支持纵向模式的 viewController 中使用它
override func shouldAutorotate() -> Bool {
if (UIDevice.currentDevice().orientation == UIDeviceOrientation.Portrait ||
UIDevice.currentDevice().orientation == UIDeviceOrientation.PortraitUpsideDown ||
UIDevice.currentDevice().orientation == UIDeviceOrientation.Unknown) {
return true;
} else {
return false;
}
}
override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.Portrait
}
关于ios - 如何禁用 UINavigationController Root View Controller 的自动旋转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36082596/