How do I force a specific UIInterfaceOrientation on an individual view in a UINavigationController?

NovaJoe picture NovaJoe · May 19, 2011 · Viewed 12.1k times · Source

Okay, so here's the situation:

I have an app in which I only want ONE specific view in a UINavigationController to have a landscape orientation. This view is a UIImageView that I'm capturing a signature on (THAT part works awesome). So, like this:

previous view --> signature view --> next view
 (portrait)        (landscape)       (portrait)

I can't seem to find a good way to force the device orientation to landscape on that signature screen. It'll never make sense to have a portrait orientation on the signature view because there's really not adequate room for signing in that screen width.

So, any bright ideas on how to accomplish this? I've considered possibly doing the signature view modally, thus breaking out of the navigation controller. Thoughts?

Answer

Mikhail picture Mikhail · Feb 18, 2013

You can try to force Device to rotate to necessary orientation - but you need to handle it manually (in addition to overriding UIViewController orientation handling methods).

To rotate device you can use next methods:

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight];

But in it may not work in all situations...

Also available undocumented approach:

[[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:")
                                       withObject:(__bridge id)((void*)UIInterfaceOrientationLandscapeLeft)];