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
To disable orientations for a particular View Controller, you should now override supportedInterfaceOrientations
and preferredInterfaceOrientationForPresentation
.
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
// Return a bitmask of supported orientations. If you need more,
// use bitwise or (see the commented return).
return UIInterfaceOrientationMaskPortrait;
// return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
// Return the orientation you'd prefer - this is what it launches to. The
// user can still rotate. You don't have to implement this method, in which
// case it launches in the current orientation
return UIInterfaceOrientationPortrait;
}
If you're targeting something older than iOS 6, you want the shouldAutorotateToInterfaceOrientation:
method. By changing when it returns yes, you'll determine if it will rotate to said orientation. This will only allow the normal portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
// Use this to allow upside down as well
//return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
Note that shouldAutorotateToInterfaceOrientation:
has been deprecated in iOS 6.0.

- 65
- 8

- 11,546
- 5
- 41
- 64
-
2If the view controller is in a navigation controller, then the navigation controller is where these need to be implemented. – Mr Rogers Sep 27 '16 at 21:40
-
@MrRogers I did so, but it doesn't work. See http://pastebin.com/dLfLLP2j Every controller implements supportedInterfaceOrientations correctly. The first view controller correctly shows in portrait even when the app is launched from the device in home screen on the iPhone Plus. But when I navigate to another controller, rotate the device back and forth to set the other controller to landscape, and come back, the first controller is now in landscape. What I want is for the first controller to be in portrait and the second one to be .all. – Kartick Vaddadi Mar 06 '17 at 12:32
-
1I suggest relacing `NSUinteger` from `supportedInterfaceOrientations` (first line of code) to `UIInterfaceOrientationMask`. Xcode 8 warns about "Conflicting return type in implementation of 'supportedInterfaceOrientations': 'UIInterfaceOrientationMask' (aka 'enum UIInterfaceOrientationMask') vs 'NSUInteger' (aka 'unsigned long')" and it makes sens. Thanks for your answer – GabLeRoux Aug 18 '17 at 20:14
Xcode 5 and above
- Click your project in the Project Navigator in the left sidebar to open the project settings
- Go to the General tab.
- Uncheck the options you don't want in the Deployment Info section, under Device Orientation

- 143,130
- 81
- 406
- 459

- 21,291
- 15
- 93
- 123
-
1I can't deselect Landscape on mine. It turns them back on immediately. Also, if I delete them from the Info.plist, it puts them back. – Almo Dec 20 '14 at 20:43
-
@skywinder what about situation if there is not exists Main Interface? – SBotirov Sep 26 '20 at 17:19
Xcode 4 and below
For those who missed it: you can use the project settings screen to fix orientations throughout the app (no need to override methods in every controller):
It's as simple as toggling the supported interface orientations. You can find by clicking on your Project in the left panel > the app target > Summary tab.

- 143,130
- 81
- 406
- 459

- 2,361
- 28
- 30
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

- 596
- 1
- 5
- 14
-
2I just tried this, but I had to replace "Supported interface orientation" with "Supported interface orientations (iPhone)", otherwise it overrode the iPad setting. – bugloaf Oct 03 '19 at 14:51
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:
In my case, my app will now only support portrait orientation.

- 1,314
- 12
- 36
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.
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.
Now you need to deselect all modes except Portrait for iPad. See below screenshot.
Now you successfully disabled all modes except Portrait for all devices.

- 16,698
- 6
- 112
- 113
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.

- 5,640
- 3
- 58
- 47
Swift 3 If you have a navigationController, subclass it like this (for portrait only):
class CustomNavigationViewController: UINavigationController {
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return UIInterfaceOrientationMask.portrait
}
override var preferredInterfaceOrientationForPresentation: UIInterfaceOrientation {
return UIInterfaceOrientation.portrait
}
}

- 1,808
- 22
- 27
Removing the method shouldAutorotateToInterfaceOrientation
from your class entirely also works. If you don't plan on rotating then it makes no sense to have the method in your class, the less code the better, keeps things clean.

- 143,130
- 81
- 406
- 459

- 3,417
- 8
- 43
- 58
-
This answer is now obsolete; `shouldAutorotateToInterfaceOrientation` has been deprecated for years. – Mark Amery Jan 22 '16 at 19:22
-
@MarkAmery https://developer.apple.com/reference/uikit/uiviewcontroller/1621419-shouldautorotate doesn't have a deprecation notice. – Kartick Vaddadi Mar 06 '17 at 12:35
-
@VaddadiKartick It's also a different method to the one mentioned in this answer; I'm unsure what your point is. – Mark Amery Mar 06 '17 at 12:37
-

- 1,987
- 18
- 24
-
1Any idea why this doesn't work. I have this button selected in Xcode settings/Info.plist and then deselected them for iphone, checked Info.plist that there is only single entry for portrait mode. But on iPhone app stills enables rotation on each screen – Michał Ziobro Sep 20 '19 at 07:51
-
@MichałZiobro You must specify it in your .plist as well. See answer by Anonimys – Micah Montoya Jan 12 '22 at 15:26
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.

- 151
- 1
- 9