My app runs in portrait mode, but i want to show one screen in landscape mode only as it is a chart. What do i add to my uiviewcontroller to force it into landscape mode only?
-
try this for iOS 7: http://stackoverflow.com/questions/22491786/force-landscape-viewcontroller-in-ios-7/22491787#22491787 – Fede Cugliandolo Mar 19 '14 at 00:12
3 Answers
I'm sorry but this answer will be very short: If you're using the UINavigationController, you can't. The answer @jer gives is therefore incorrect. The Apple documentation states:
All child view controllers in your UITabBarController or UINavigationController do not agree on a common orientation set.
I recently had this question answered on a bounty and my app rejected in the process. Read up on that here: How to constrain autorotation to a single orientation for some views, while allowing all orientations on others?
The only solution you have, is to throw away the UINavigationController and rewrite it with something of your own.
-
Ah thanks, the UINavigationController will be the issue then. Thanks for the link, I'll have a read. – lps Mar 17 '11 at 14:13
-
2For clarity, nothing was noted previous about a nav controller, and I'm not a mind reader. Your statement implies that this was known information at the time I made my answer, which it was not. – jer Mar 17 '11 at 15:10
-
Sorry @jer, I meant no bashing, nor did I downvote or anything. I had a very tough struggle with this issue, and many people came up with the same answer of different shouldAutorotateToInterfaceOrientation: implementations. It makes absolutely no sense the way it's implemented by Apple, which is why it's even harder to find the solution to this seemingly simple problem. Cheers, EP. – epologee Mar 17 '11 at 15:15
-
1I was wracking my brain on this. Such a simple oversight. Thanks! – Leachy Peachy Jan 03 '12 at 23:22
-
Thanks! I had to change my segue from push to Modal and just add a close button but my WebViewViewController now will go landscape-- thanks! – RyanG Oct 03 '12 at 14:47
-
I've been trying out different implementation of `shouldAutorotateToInterfaceOrientation:` for the past couple of days to get this thing done! Now only I came across your answer. Guess I'll have to include xib files and storyboards together. – Isuru Feb 22 '13 at 06:45
-
@Isuru have a look a one of the newer questions on the other post, it seems there are ways to do this as of iOS 6: http://stackoverflow.com/a/14802980/432782 – epologee Feb 22 '13 at 10:17
By presenting and dismissing a view controller modally you can force an orientation. Set animations to "NO" and you can do this without the user even realizing it occurred.
You can read more about this Josh's answer on Is there a documented way to set the iPhone orientation?
I consider it a bit of a hack, but I've successfully implemented code using this premise to force any device orientation.
You implement shouldAutorotateToInterfaceOrientation:
and have it return only YES for UIInterfaceOrientationIsLandscape(param)
where param
is the parameter you declared for the method.
This will support landscape left and landscape right, instead of locking you to only one landscape orientation.

- 20,094
- 5
- 45
- 69
-
I tried that but it still shows the screen as portrait. I added: - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft); } – lps Mar 17 '11 at 13:45