在iPad上锁定方向并禁用旋转 [英] Lock orientation and disable rotation on iPad

查看:1256
本文介绍了在iPad上锁定方向并禁用旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've got the following code which works fine on iPhone, but not on iPad. It should lock the orientation on landscape and disable autorotation only for THIS viewcontroller (not for the whole app - NOT changing attributes in the project/info.plist file):

override var shouldAutorotate : Bool {
        return false
}

viewDidLoad()

let landscapeValue = UIInterfaceOrientation.landscapeRight.rawValue
UIDevice.current.setValue(landscapeValue, forKey: "orientation")

如何将方向锁定到横向并禁用当前ViewController的旋转(就像它已经完全在iPhone上工作一样)?

How can I lock the orientation to landscape and disable rotation for my current ViewController (like it is already perfectly working on iPhone)?

我的规格:

XCode - 9.1 Build 9B55

XCode - 9.1 Build 9B55

Swift - 4.0.2

Swift - 4.0.2

在iPad Air上测试 - iOS 10.3.3

Tested on iPad Air - iOS 10.3.3

推荐答案

我的问题的答案实际上非常简单。您必须在项目的部署信息中激活需要全屏。之后,iPad的行为与使用此代码的iPhone相同。

The answer to my question was actually quite simple. You have to activate Requires full screen in Deployement Info of your project. After that the iPad behaves the same as the iPhone with this code.

这篇关于在iPad上锁定方向并禁用旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆