小编Dav*_*id 的帖子

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

我有以下代码可以在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

orientation ipad screen-rotation ios swift

2
推荐指数
1
解决办法
873
查看次数

标签 统计

ios ×1

ipad ×1

orientation ×1

screen-rotation ×1

swift ×1