【问题标题】:Fix orientation on iPad修复 iPad 上的方向
【发布时间】:2016-04-30 21:54:39
【问题描述】:

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

【问题讨论】:

标签: ios xcode swift ipad orientation


【解决方案1】:

您可以在设置中“允许”所有 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
}

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

【讨论】:

  • @Kidlcarus271:完美运行!
猜你喜欢
  • 2013-11-17
  • 2023-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-20
  • 1970-01-01
相关资源
最近更新 更多