How can I force landscape for all views in Xcode - ios

I tried to set the device orientation to landscape only (left & right) in the General tab of the target and also in the Info tab for iPad and iPhone, but portrait mode is still supported/enabled. Is this a Xcode bug or does anyone know why portrait mode is still supported even though I disabled it in both places? Preferably I would like to achieve it without setting it in code. I am using Xcode 13.

After playing around for a while I saw, that the portrait mode is still set in the Build Settings tab even though I disabled it in the General and Info tab. Just click on your Target -> Build Settings -> search for 'Orientation' and remove the portrait one if there is any.

Related

ios simulator won't stay horizontal even when landscape mode is ticked

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:

Locking a project into portrait in Xcode?

I have just begun creating a new Xcode project, and noticed that how I normally remove the function to have the app in landscape; a tick box under device orientation within the general tab of the project; has disappeared.
Has this orientation setting moved elsewhere, or must I now code it to lock it into portrait only?
Also, I am working in objective-c.
Thanks.
Click on your project on the left menu, next uncheck Landscape mode in Device Orientation:

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

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

Device orientation in Xcode does not seem to work properly

In my project I have only options "portrait" and "upside down" selected. The two of landscape options are not checked. But when I run it whether on a device or on simulator and turn it right or left the app becomes landscape. It should not, what could be wrong?
Ups, sorry i didn't noticed the iPad tab which also containes checkboxes with checked landscape

Screen Rotation in iOS

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.

Resources