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?
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.
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.
Works for me!
Open info.plist as source code, you will see these properties:
UISupportedInterfaceOrientations : For iPhone
UISupportedInterfaceOrientations~ipad : For iPad
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.
Done! Good Luck
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.
Then select the iPad deployment info by selecting only the iPad. Remove the landscape selections 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).
Flipping back to iPad only will show that the settings still remain.
The info.plist will also reflect the changes made to iPhone and iPad using the Deployment Info.
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:
Specifically:
Select iPad and deselect iPhone
Set the orientations support as required
Un-set Supports multiple windows
Switch back to iPhone only
This image is enough, only select the Portrait.
edit for Shyam's comment
Xcode8.3.3 MacOS Sierra v10.12.5
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.
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...
xCode 11
project ----> General -----> Devices ---->iPad
Related
I want to support both portrait and landscape on iPad, but only portrait on iPhone.
Is it possible? What is the best way to do this?
There's only one set of "Device orientation" checkboxes in the project settings.
You can edit the info.plist file as per your needs manually.
Notice, iPad orientation is separate from the default phone orientation.
There's only one set of "Device orientation" checkboxes in the project settings.
Yes, and you use it like this:
Check just iPhone.
Check just portrait.
Check just iPad.
Check all four orientations.
Check both iPhone and iPad.
I know it's confusing, but that will do what you want.
I'm developing a swift project with XCode and I need my app to run only in landscape mode. I ticked the option like it shows here:
but still, when I launch the app the simulator stays in portrait.
I know i can rotate it with command + left or right but I'd prefer XCode to do that for me.
You have to set it too in your info.plist key Supported interface orientations:
I am making an ipad app, and i set the the app to only portrait, but it still works in landscape? Why is this happening only on an ipad? How do i fix this?
Note: if the answer is in code, please write it in swift.
In xcode select your project. Go to Targets -> General, scroll down and you can select the Orientation as portrait only.
You can also make change to info.plist file to select proper orientations for Supported interface orientations (iPad)
In deployment Info section you can select your app orientation to support.
I need some help regarding "Screen Rotation". I am creating this application in Landscape mode but I also want to be able to turn the iPad to Portrait mode. I am trying something different and making the application inside the viewcontroller. Basically copy and paste a view controller over and over. My issue is that even after I select, "Portrait" to be the ViewControllers Mode it still changed to landscape when i the iPad is turned to Landscape mode. I hope this made sense. Any answers are greatly appreciated!
If you're setting the supported orientation modes under the 'Deployment Info' section of your project file in Xcode, might be worth double checking that you are setting the modes for iPad rather than iPhone if you setup your project as a Universal app.
Why is xcode asking for landscape launch images?
My app doesn't support landscape in neither iPhone nor iPad
You need to make sure that the Info.plist reflects the fact that your app doesn't support landscape. It's not enough that none of your view controllers support it. Make sure the "Supported Interface Orientations" in the "Summary" tab for your target only has the portrait orientations selected in both the iPhone/iPod and iPad Deployment Info sections. These sections are equivalent to the UISupportedInterfaceOrientations and UISupportedInterfaceOrientations~ipad keys in Info.plist. That is, editing them in the "Summary" tab also edits your Info.plist for you.
Apparently it was an issue with the xcode beta release