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

标签 ios swift ipad orientation screen-rotation

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

相关文章:

android - Ionic 应用程序中的 "cordova already defined"

ios - 我在理解如何使用自动布局的逻辑时遇到问题

json - 从 Core Data 获取 JSON 格式的特定项目

swift - 第一次保存图像后,我的图像保存功能中的几行不运行

php - 我该如何使用 Facebook 访问 token ?

iphone - ASIHTTPRequest 随每个请求发送数据

ios - Xcode编译中如何集成.proto文件?

ios - 使用 iPhone 将 mac 检测为 iBeacon

ios - 使用来自 NSAttributedString (OAExtensions) 的 initWithHTML

ios - CIColorInvert 和 CIColorMatrix 没有正确反转图像