我有以下代码,它在 iPhone 上运行良好,但在 iPad 上运行不佳。它应该锁定横向方向并仅针对此 View Controller 禁用自动旋转(不是针对整个应用程序 - 不要更改项目/info.plist 文件中的属性):
override var shouldAutorotate : Bool {
return false
}
在 viewDidLoad()
中:
let landscapeValue = UIInterfaceOrientation.landscapeRight.rawValue
UIDevice.current.setValue(landscapeValue, forKey: "orientation")
如何将当前 ViewController 的方向锁定为横向并禁用旋转(就像它已经在 iPhone 上完美运行一样)?
我的规范:
XCode - 9.1 版本 9B55
swift - 4.0.2
在 iPad Air - iOS 10.3.3 上测试
最佳答案
我的问题的答案其实很简单。您必须在项目的部署信息中激活需要全屏。之后,iPad 的行为与使用此代码的 iPhone 相同。
关于ios - 在 iPad 上锁定方向并禁用旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48423833/