Swift 3 如何锁定方向

标签 swift swift3 orientation

我试图将我的 viewController 锁定为纵向,而不必依赖部署信息,但我的以下代码不起作用

override var shouldAutorotate: Bool {
    return false
}

override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
    return UIInterfaceOrientationMask.portrait
}

 override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
    return UIInterfaceOrientation.portrait
}

override func viewDidLoad() {
    super.viewDidLoad()

}

最佳答案

您可以在 AppDelegate 中尝试这个。这将锁定所有 viewController 的方向

func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask {
    return UIInterfaceOrientationMask(rawValue: UIInterfaceOrientationMask.portrait.rawValue)
}

关于Swift 3 如何锁定方向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40395367/

相关文章:

swift - 使用 Swift 3 按下时动画单元格

ios - 肖像应用程序。风景视频。 shouldAutoRotate 未运行

react-native - 如何检测 landscapeRight 到 landscapeLeft 方向的变化?

Swift,呈现一个带有标签栏的新 uiview

ios - anyObject 的 NSUserDefaults arrayForKey 值没有成员 removeAtIndex (Swift)

ios - 在 swift 4.1 中,你如何监听 View Controller 何时完成旋转?

swift - 从具有多个 child 的 Firebase 数据库中检索

swift - 实例成员 '$isBrowsingWebsite' 不能用于类型 'MapPinSheetSectionOneView_Previews'

ios - 方法不会覆盖其父类(super class) swift 3.0 错误中的任何方法

android - getRotation 始终返回零