Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 837
NovaJoe Avatar asked May 19 '11 21:05

NovaJoe


People also ask

How do I change the orientation in react native?

For Android, open the AndroidManifest. xml file and within the activity element add 'android:screenOrientation="portrait"' to lock to portrait or 'android:screenOrientation="landscape"' to lock to landscape.

Which setting in an IOS device do you need to enable if you want to test the application for various orientation modes?

From ios 10.0 we need set { self. orientations = newValue } for setting up the orientation, Make sure landscape property is enabled in your project.


2 Answers

Just override this UIViewController method to only return true for landscape like so and the iphone will be forced to rotate to that device orientation, since it has no other option.

- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
like image 35
Nirma Avatar answered Oct 21 '22 22:10

Nirma


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)];
like image 71
Mikhail Avatar answered Oct 21 '22 21:10

Mikhail