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

问题描述 投票:2回答:1

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

斯威夫特 - 4.0.2

在iPad Air上测试 - iOS 10.3.3

ios swift ipad orientation screen-rotation
1个回答
3
投票

我的问题的答案实际上非常简单。您必须在项目的Deployement Info中激活Requires full screen。之后,iPad的行为与使用此代码的iPhone相同。

© www.soinside.com 2019 - 2024. All rights reserved.