我知道这个问题已经在 here 中提出过, here和 here .我尝试了所有可能的方法,但没有成功。
我正在尝试在 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;
}
但无法在横向模式下旋转它。
最佳答案
执行以下操作:
- 在一般信息屏幕中启用所需的方向
在每个
ViewController
中,用 true 或 false 覆盖自动旋转功能
(true
对于应该旋转的那个,false
对于其他的):override var shouldAutorotate: Bool { return true }
希望对您有所帮助:)
关于ios - 只允许一个 View Controller 的所有方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29655784/