锁定方向并在iPad上禁用旋转

Dav*_*id 2 orientation ipad screen-rotation ios swift

我有以下代码可以在iPhone上正常运行,但不能在iPad上运行。它应该仅在此ViewController上锁定方向的横向方向并禁用自动旋转(对于整个应用程序不禁用-请勿更改project / info.plist文件中的属性):

override var shouldAutorotate : Bool {
        return false
}
Run Code Online (Sandbox Code Playgroud)

并在viewDidLoad()

let landscapeValue = UIInterfaceOrientation.landscapeRight.rawValue
UIDevice.current.setValue(landscapeValue, forKey: "orientation")
Run Code Online (Sandbox Code Playgroud)

如何将方向锁定为横向并禁用当前ViewController的旋转(就像它已经在iPhone上正常运行一样)?

我的规格:

XCode-9.1内部版本9B55

迅捷-4.0.2

在iPad Air上进行了测试-iOS 10.3.3

Dav*_*id 5

我的问题的答案实际上很简单。您必须在项目的“ 部署信息”中激活“ 需要全屏显示”。之后,iPad的行为与带有此代码的iPhone相同。