ios - 如何禁用 UINavigationController Root View Controller 的自动旋转?

标签 ios objective-c swift user-interface

我需要在我的应用程序中支持所有界面方向掩码。 有些 View Controller 不应该自动旋转(它只支持纵向),但应用程序仍然需要支持所有方向。 Expected result

我尝试设置 shouldAutorotate = true; UINavigationController 中的 supportedInterfaceOrientations = AllshouldAutorotate = 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/

相关文章:

iphone - 在选择时更改 UITableViewCell 布局

iOS 5 推特框架 : Tweeting without user input and confirmation (modal view controller)

ios - 从 url 获取数据时,数据不会附加到全局变量中

ios - 如何在按钮上设置自定义指针效果(Objective-C)?

objective-c - 对文件的一些操作

swift - 可选 var 未设置

iPhone 网络摄像头馈送

ios - 将 NSString 转换为 const char string[]

IOS 9 - subview 上的 UIButton 不触发 IBAction socket

ios - NSPersistentContainer 默认创建什么样的持久化存储?