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

9

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?

Subadar answered 8/11, 2015 at 3:3 Comment(2)
When you make universal app, the orientation settings for iPad and iPhone are separate. Check again if you've disabled for iPad too.Jessikajessup
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!Flurried
R
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.

Rizzi answered 8/11, 2015 at 3:3 Comment(1)
Be sure that you select the 'Requires Full Screen' box for iPad, or your app will fail validation.Hipolitohipp
R
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.

Ramakrishna answered 30/8, 2017 at 18:8 Comment(5)
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!Reichenberg
Work like charm! Thank you!Repeal
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?Flittermouse
yeah - if you tick the "Requires full screen" option, you can submit it locked to a single orientation.Sporule
it just adds them back when you run it after thatCementite
R
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

Repeal answered 11/7, 2018 at 3:43 Comment(3)
It's working for me also, because this bug is still in Xcode 11.2 but it is working on every version of Xcode.Healall
Works perfectly :)Spaniel
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 #32560224Amaze
B
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

Brawl answered 20/6, 2020 at 23:40 Comment(2)
Wow thanks. This is one of the most confusing settings I've ever seen.Gomuti
Thanks so much! What a counter-intuitive UX, Apple really made me think different...Cle
U
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
Unto answered 6/4, 2021 at 17:19 Comment(2)
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...Kelleykelli
Wow, this worked for me after trying a lot of solutions.Estrone
D
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

Dionisio answered 4/5, 2017 at 6:56 Comment(13)
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.Nikolai
@Nikolai what's your appdelegate setting. what's your orientation set. refer to my this post https://mcmap.net/q/330736/-how-to-change-a-view-from-portrait-mode-to-landscape-mode-and-lock-it/6521116Dionisio
No code written in Appdelegate on orientation. I enable only portrait mode in Project-Target- General tab.Nikolai
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).Nikolai
@Nikolai glad it helps. Your upvote will be appreciated.Dionisio
@Shyam Xcode8.3.3 should have this project config too. I use xcode8.2, xcode8.3.3 should not have much difference here.Dionisio
@KrisRoofe , sadly no. :( the options in the screenshot you attached, exist no more.Betulaceous
@Betulaceous sorry my macpro is not at hand. I'll upgrade my xcode on monday and check it.Dionisio
@Betulaceous 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.Dionisio
@KrisRoofe , no worries. Thanks for your time.Betulaceous
@Shyam, you can check my answer now.Dionisio
@KrisRoofe, I've submitted an answer, because it is not possible to attach a screenshot. Thanks again, for your time.Betulaceous
Thanks! The easiest and the best answer.Filthy
D
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.

Dance answered 18/3, 2019 at 6:9 Comment(0)
F
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...

Flittermouse answered 26/1, 2020 at 19:36 Comment(0)
Z
-1

xCode 11

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

iPad

Zavala answered 5/2, 2020 at 8:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.