iosswiftrotationuideviceorientation

UIDevice set orientation not working on iPad


What I'm trying to achieve is that when user presses a button, to programmatically simulate device rotation to landscape. I've this code that is working for iPhone devices but not for iPads

let value = NSNumber(integerLiteral: UIDeviceOrientation.landscapeRight.rawValue)
UIDevice.current.setValue(value, forKey: "orientation")
ViewController.attemptRotationToDeviceOrientation()

Is there a way to achieve the same on iPads?


Solution

  • Well the direct solution to this is pretty simple but it has a drawback. It is fixed by setting Requires Full Screen to true in the project settings General section. Of course, this means your app won't support multitasking, which may not be suitable depending on your app.

    enter image description here