我已经获得了以下代码,可以在iPhone上正常使用,但不能在iPad上运行。它应该锁定横向方向并仅为此视图控制器禁用自动旋转(不适用于整个应用程序 - 不更改project / 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 Build 9B55
Swift - 4.0.2
在iPad Air上测试 - iOS 10.3.3
答案 0 :(得分:3)
我的问题的答案实际上非常简单。您必须在项目的部署信息中激活需要全屏。之后,iPad的行为与使用此代码的iPhone相同。