How can I disable landscape orientation?

Viewed 61139

I am making an iPhone app and I need it to be in portrait mode, so if the user moves the device sideways, it does not automatically rotate. How can I do this?

11 Answers

Most simple solution separate for iPhone and iPad (Universal) - its remove unnecessary orientation in the info.plist file or Project -> Info -> Custom iOS Target Properties.

Just add or remove orientation item from list:

  • Supported interface orientation for iPhone
  • Supported interface orientations (iPad) for iPad

enter image description here

In Xcode 13.3.1, simply unchecking undesired orientations does not prevent an app from supporting all rotations. It is necessary to enter the Build Settings tab and manually remove any orientations from the following fields that you do not wish to support: Desired Orientation Values

In my case, my app will now only support portrait orientation.

If you want to disable landscape orientation for both iPhone and iPad.

Go to Targets and Go to the General tab. See the below screen and deselect landscape left and landscape right.

enter image description here

Here in this case only iPhone landscape mode will be disabled not for iPad. For iPad all modes are anabled. If you want select device option from Universal to iPad. It will looks like this. See below screen.

enter image description here

Now you need to deselect all modes except Portrait for iPad. See below screenshot.

enter image description here

Now you successfully disabled all modes except Portrait for all devices.

If you created a new Xcode 13.3 project and unchecked unnecessary orientation checkmarks in the Project > General > Deployment and it didn't help. Check the Target > Build Settings - there are 2 rows which override global settings.

Build settings

Xcode 8, Xcode 9, Xcode 10 and above

enter image description here

Also, make changes in Info.plist file

enter image description here

I've had the same problem on Xcode 13.0 even though I set the device orientation only Portrait.

Adding these 2 lines to Info.plist solved my problem.

info.plist

Related