2

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

David
  • 273
  • 2
  • 20
  • This [answer](https://stackoverflow.com/a/33454271/7737270) and this [answer](https://stackoverflow.com/a/30429315/7737270) might help you. – Abdullah Al Farooq Jan 24 '18 at 13:55
  • regarding 1): as I said, this will lock my whole app not only one viewcontroller to the desired orientation. regarding 2): I don't have any NavigationController as parents on the controller in which I'm using this code. – David Jan 24 '18 at 13:57

1 Answers1

9

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.

David
  • 273
  • 2
  • 20