简体   繁体   中英

Lock orientation and disable rotation on iPad

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
}

and in viewDidLoad() :

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

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

My Specs:

XCode - 9.1 Build 9B55

Swift - 4.0.2

Tested on iPad Air - iOS 10.3.3

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM