How could I allow my universal app written in Swift on iOS 8.3 SDK to support only portrait mode on iPhone, but both portrait and landscape mode on iPad?
I know in the past this has been done in AppDelegate. How could I do this in Swift?
Make sure that Rotation Lock is off: Swipe down from the top-right corner of your screen to open Control Center. Then tap the Rotation Lock button to make sure it's off.
To reiterate, this issue of the screen being oriented in Portrait mode is controlled by the App. It is the App Developer that codes the App to display in either Portrait or Landscape orientation. Apple has no control over how third-party Apps choose to display their content.
From ios 10.0 we need set { self. orientations = newValue } for setting up the orientation, Make sure landscape property is enabled in your project.
You can do it programmatically, or better yet, you can simply edit your project's Info.plist (Which should be more practical, since it's a global device configuration)
Just add "Supported Interface orientations (iPad)" key
You could do it programmatically
override func shouldAutoRotate() -> Bool { if UIDevice.currentDevice().userInterfaceIdiom == .Pad { return true } else { return false } }
and then
override func supportedInterfaceOrientations() -> Int { return UIInterfaceOrientation.Portrait.rawValue }
or any other rotation orientation that you wish to have by default.
That should detect if the device you're using is an iPad and allow rotation on that device only.
EDIT: Since you only want portrait on iPhone,
override func supportedInterfaceOrientations() -> Int { if UIDevice.currentDevice().userInterfaceIdiom == .Phone { return UIInterfaceOrientation.Portrait.rawValue } else { return Int(UIInterfaceOrientationMask.All.rawValue) } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With