修复 iPad 的方向

Fix orientation on iPad

我的应用只需要 Portrait 和 PortraitUpsideDown。在目标的部署信息中我只检查了这两个。在 Info.plist 中,所有四个都可用。当我从 Info-plist 中删除 Landscapes 时,Xcode 不让我构建,说我需要支持所有四个。现在,在 运行 应用程序通过 TestFligh 后,它仍然 returns Landscape 尽管在部署信息中未选中。我怎样才能摆脱这个?

您可以 "allow" 设置中的所有 4 个选项,然后您自己控制方向。

我会在里面创建一个自定义 UINavigation 控制器 (Swift):

import UIKit

class MyCustomNavigationController: UINavigationController {
    override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
        return (visibleViewController?.supportedInterfaceOrientations())!
    }

    override func shouldAutorotate() -> Bool {
        return (visibleViewController?.shouldAutorotate())!
    }
}

然后,在您想要强制进入特定方向的每个 ViewController 中,您包括:

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    return UIInterfaceOrientationMask.Landscape // Or portrait
}

override func shouldAutorotate() -> Bool {
    return true
}

这样您可以允许所有方向,但仍然保持对视图本身的控制。如果您希望所有视图都相同(例如景观),您可以为所有视图控制器创建一个自定义基础 class,其中包含第二组代码,并且您不必将其包含在每个人 VC.