我试图将我的 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/