ios - 只允许一个 View Controller 的所有方向

标签 ios xcode swift orientation uiinterfaceorientation

我知道这个问题已经在 here 中提出过, herehere .我尝试了所有可能的方法,但没有成功。

我正在尝试在 Swift (iOS 8) 中开发一个应用程序,其中只有一个 View Controller 可以在所有方向上查看,其他 View Controller 只能纵向查看。

为此,我在 Target->General->Device Orientation 中仅启用了Portrait 模式(因为我希望应用程序仅在一个 View Controller 之外的纵向模式下运行)。

我已将以下代码添加到我想在所有方向上操作的 View Controller :

override func supportedInterfaceOrientations() -> Int {
    return Int(UIInterfaceOrientationMask.All.rawValue)
}

override func preferredInterfaceOrientationForPresentation() -> UIInterfaceOrientation {
    return UIInterfaceOrientation.LandscapeLeft;
}

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

但无法在横向模式下旋转它。

最佳答案

执行以下操作:

  1. 在一般信息屏幕中启用所需的方向
  2. 在每个 ViewController 中,用 true 或 false 覆盖自动旋转功能
    (true 对于应该旋转的那个,false 对于其他的):

    override var shouldAutorotate: Bool {
        return true
    }
    

希望对您有所帮助:)

关于ios - 只允许一个 View Controller 的所有方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29655784/

相关文章:

iOS 套接字 : communication with Maya

ios - 在 OpenGL ES 2.0 iOS5 模板中,程序无需着色器即可运行。怎么会?

ios - 有没有一种好方法可以为您的 iOS 应用程序测试不同时区?

ios - swift 2.0 prepareForSegue 不工作

ios - 如何按我当前的位置过滤 Google Places 自动完成结果? swift

IOS自动续订订阅状态获取不到

ios - 在我停止 Beta 测试后,运行 Beta 版的人是否对应用内购买收费(已选择“不可用于测试”)

ios - 连接 html 嵌入字符串中的 swift 变量

cocoa - IB中无法绑定(bind)NSSlider?

ios - 无法检索额外的 header - Mailcore