59

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?

LF00
  • 27,015
  • 29
  • 156
  • 295
Eugene
  • 3,417
  • 5
  • 25
  • 49
  • 10
    When you make universal app, the orientation settings for iPad and iPhone are separate. Check again if you've disabled for iPad too. – Adil Soomro Nov 08 '15 at 03:07
  • Don’t do it! It is annoying for actual iPad users! Many of them, me included, never use the device in portrait mode, especially when keyboard is attached! – Megan Caithlyn Jun 27 '22 at 20:36

10 Answers10

95

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.

Pavan Gandhi
  • 1,729
  • 1
  • 22
  • 36
66

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.

Tomasz Czyżak
  • 1,118
  • 12
  • 13
  • 7
    This is the best answer. I had selected 'Portrait' in the General settings, still the app would rotate on an iPad but not on the iPhone. Changing the Info.plist did the job. I wonder why 2 settings are to be changed for getting one thing done! – zeuschyant8 Mar 16 '18 at 12:43
  • Work like charm! Thank you! – EK Chhuon Jul 11 '18 at 02:07
  • when i remove and try to submit the app to appstore there is error in app validation.. and it says that for ipad it needs all the 4 entries... is there any way to bypass that? and submit the app successfully? – MD Sazid Hasan Dip Jan 26 '20 at 19:10
  • yeah - if you tick the "Requires full screen" option, you can submit it locked to a single orientation. – Mark B May 04 '20 at 13:36
  • it just adds them back when you run it after that – Dennis Barzanoff Jun 07 '21 at 15:26
51

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

Community
  • 1
  • 1
EK Chhuon
  • 1,105
  • 9
  • 15
  • 1
    It's working for me also, because this bug is still in Xcode 11.2 but it is working on every version of Xcode. – Rana Ali Waseem Nov 20 '19 at 15:24
  • Works perfectly :) – logeshpalani31 Jan 24 '20 at 07:54
  • 1
    Also for this to work you have to set "Requires full screen" to true if you haven't already. Or your app will fail App Store Connect Validation and you'll see this error https://stackoverflow.com/questions/32559724/ipad-multitasking-support-requires-these-orientations – Paul Mayer May 23 '20 at 11:46
34

Applies to Xcode 11, 12, 13 (Fixed in Xcode 14)

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

Marcy
  • 4,611
  • 2
  • 34
  • 52
12

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
HughHughTeotl
  • 5,439
  • 3
  • 34
  • 49
  • The Device Orientation checkboxes are confusing. I had iPhone and iPad enabled, with Portrait checked, which it would be fair to assume applies to both, but I had to uncheck iPhone and then uncheck all the other enabled iPad orientations that aren't shown by default, then recheck iPhone... – alstr Jun 24 '21 at 11:27
  • Wow, this worked for me after trying a lot of solutions. – Binh Ho Apr 20 '22 at 09:57
8

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

LF00
  • 27,015
  • 29
  • 156
  • 295
  • The device mode is Universal, uncheck "Device Orientation" except Portrait. and run the application on iPad device, the observation little bit strange to me, the orientation still happening. – KkMIW May 12 '17 at 12:42
  • @KkMIW what's your appdelegate setting. what's your orientation set. refer to my this post http://stackoverflow.com/q/43773075/6521116 – LF00 May 12 '17 at 12:47
  • No code written in Appdelegate on orientation. I enable only portrait mode in Project-Target- General tab. – KkMIW May 15 '17 at 05:23
  • 3
    I resolved the issue -> Open General tab change Devices to iPad default its select all the orientation options, de-select the orientation for landscape left and right and change it back to again Universal. run the application (hurry resolved). – KkMIW May 15 '17 at 05:31
  • @KkMIW glad it helps. Your upvote will be appreciated. – LF00 May 15 '17 at 05:39
  • @Shyam Xcode8.3.3 should have this project config too. I use xcode8.2, xcode8.3.3 should not have much difference here. – LF00 Jun 17 '17 at 10:33
  • @KrisRoofe , sadly no. :( the options in the screenshot you attached, exist no more. – Shyam Jun 17 '17 at 11:46
  • @Shyam sorry my macpro is not at hand. I'll upgrade my xcode on monday and check it. – LF00 Jun 17 '17 at 13:07
  • @Shyam I'm afraid I cannot finish upgrade today, I only download 2.09GB of 4.51GB of the packages for about 4 hours. So I may check it later today or tomorrow morning when it finished. – LF00 Jun 19 '17 at 05:51
  • 1
    @KrisRoofe , no worries. Thanks for your time. – Shyam Jun 19 '17 at 05:56
  • @Shyam, you can check my answer now. – LF00 Jun 19 '17 at 08:46
  • @KrisRoofe, I've submitted an answer, because it is not possible to attach a screenshot. Thanks again, for your time. – Shyam Jun 19 '17 at 10:43
  • 1
    Thanks! The easiest and the best answer. – levan Apr 11 '19 at 08:22
8

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.

Nostradamus
  • 1,497
  • 3
  • 20
  • 34
4

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...

MD Sazid Hasan Dip
  • 1,425
  • 2
  • 14
  • 29
-1

xCode 11

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

iPad

Ahmed Abdallah
  • 2,338
  • 1
  • 19
  • 30
-1
 <key>UISupportedInterfaceOrientations~ipad</key>
<array>
    <string>UIInterfaceOrientationPortrait</string>
    <string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>UIRequiresFullScreen</key>
<true/>

Highlighted code is must. Otherwise apple's will reject when you try to publish

enter image description here

for more details : https://www.appsloveworld.com/swift/100/3/how-do-i-disable-landscape-orientation-on-an-ipad-app

D.A.C. Nupun
  • 495
  • 5
  • 8