How do I disable landscape-orientation on an iPad app?

IosSwiftXcodeLandscape

Ios Problem Overview


I created a completely new, single-view iOS universal Swift app. Then, I unchecked "Landscape Left" and "Landscape Right" in the app settings. I ran it on my iPhone, and hooray, it stays in portrait mode no matter how I rotate my phone. Then I ran it on my iPad, and it rotates to anything. Even upside-down portrait mode, which wasn't enabled in the first place? Am I the only experiencing this? This happens in the iPad simulator as well when I rotate with command+arrow key.

I also tried adding the following to ViewController.swift, and got the same result.

override func shouldAutorotate() -> Bool {
    return false
}

override func supportedInterfaceOrientations() -> UIInterfaceOrientationMask {
    return UIInterfaceOrientationMask.Portrait
}

Is there no way to actually disable rotating away from portrait on iPad?

Ios Solutions


Solution 1 - Ios

Its work perfectly. Dont need to write code for it.

First select project and then go in first tab "General".

Now select "Devices" option in Deployment info section is iPad and in that down select Device orientation .. In which remove checkmark from landscape Left, Right option

After done select it back device as universal and set device orientation as portrait..mode and remove check mark from landscape mode.

Now run your app in iPad and check that things. I hope it will be resolved.

Solution 2 - Ios

There are separate entries in Info.plist for iPhone and iPad supported orientations.

  • iPhone = UISupportedInterfaceOrientations
  • iPad = UISupportedInterfaceOrientations~ipad

You need to modify Info.plist and remove landscape entries for UISupportedInterfaceOrientations~ipad key.

Solution 3 - Ios

Works for me!

Open info.plist as source code, you will see these properties:

  • UISupportedInterfaceOrientations : For iPhone
  • UISupportedInterfaceOrientations~ipad : For iPad

Full Orientation Modes

Under UISupportedInterfaceOrientations~ipad remove your unwanted orientation mode. In my case, I want only Portrait Mode so I removed the rest modes and then save it.

Portrait Mode Only

Done! Good Luck

Solution 4 - Ios

Using Xcode 11

The iPhone orientation settings and iPad orientation settings can be set independently using the Deployment Info settings. No need exists to update the info.plist for orientation. Updating the Deployment Info will update info.plist for you. (This is not intuitive and may be overlooked)

For example, set the iPhone deployment info by selecting only the iPhone. enter image description here

Then select the iPad deployment info by selecting only the iPad. Remove the landscape selections here. enter image description here

Then when finished, if you want both iPhone and iPad settings, select them both. The settings will remain for both iPhone and iPad even if they differ (iPhone's orientation settings are shown but iPad's remain). enter image description here

Flipping back to iPad only will show that the settings still remain. enter image description here

The info.plist will also reflect the changes made to iPhone and iPad using the Deployment Info. enter image description here

Solution 5 - Ios

The accepted answer doesn't quite work for iOS 13 onwards, because of support for Split View.

Basically, the Supported Interface Orientations setting is ignored on iPad if you have Enable Multiple Windows set to TRUE. The rationale here is that if you are allowing your app to work in Split View then it can be squished to 'odd' dimensions which it needs to support. So by default it would need to support any orientation.

This is all a bit unintuitive, but as a result of the above, you need to set Enable Multiple Windows to FALSE in your PLIST file.

This is particularly unintuitive for iPhone-only apps because you would not unreasonably assume that the iPhone settings would carry over to iPad, providing of course that you have not set separate iPad orientation settings as other answers here have documented.

So here's a screen record of what you need to do: How to support portrait-only iPhone or iPad app

Specifically:

  1. Select iPad and deselect iPhone
  2. Set the orientations support as required
  3. Un-set Supports multiple windows
  4. Switch back to iPhone only

Solution 6 - Ios

This image is enough, only select the Portrait.

set portrait mode


edit for Shyam's comment

Xcode8.3.3 MacOS Sierra v10.12.5

enter image description here

Solution 7 - Ios

In Xcode 10 at least, for a universal app this feature is broken. For a universal app setting the orientation restriction by checking the relevant orientation only works for iPhone, you will need to go into the plist and remove the unwanted orientations under "Supported interface orientations (iPad)", where you will find all four orientations awaiting you regardless of what you checked. It's simply a bug in Xcode that apparently doesn't have a very high priority since it's been around for a while.

Solution 8 - Ios

these process of override does not work now.. and only changing the UI supported interface oriatations for ipad in info.plist will only temporarily solve the problem but will create problem when you will go for app validation and app sumbmission to app store.. For successfully validating and submitting you have to also add the key

"UIRequiresFullScreen"

you have to modify the keys like this..

<key>UISupportedInterfaceOrientations~ipad</key>
<array>
	<string>UIInterfaceOrientationPortrait</string>
	<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>UIRequiresFullScreen</key>
<true/>

I have tested this...

Solution 9 - Ios

xCode 11

project ----> General -----> Devices ---->iPad

iPad

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEugeneView Question on Stackoverflow
Solution 1 - IosPavan GandhiView Answer on Stackoverflow
Solution 2 - IosTomasz CzyżakView Answer on Stackoverflow
Solution 3 - IosEK ChhuonView Answer on Stackoverflow
Solution 4 - IosMarcyView Answer on Stackoverflow
Solution 5 - IosHughHughTeotlView Answer on Stackoverflow
Solution 6 - IosLF00View Answer on Stackoverflow
Solution 7 - IosNostradamusView Answer on Stackoverflow
Solution 8 - IosMD Sazid Hasan DipView Answer on Stackoverflow
Solution 9 - IosAhmed AbdallahView Answer on Stackoverflow