ShouldAutoRotate method not called in iOS6

I have a detailed view of a UIViewController that UIViewController from a UITableView to a UINavigationController . In the UIViewController I add several subzones (e.g. UITextView , UIImageView ).

In iOS5 I used this code to stop autorotation if my image extension was increased:

 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations if (scrollView.isZoomed) { return NO; } else { return YES; } 

}

I am trying to do the same in iOS6 using:

 - (BOOL)shouldAutorotate { return FALSE; } 

However, this method is never called, and the application continues to spin.

Can anyone help?

+3
iphone xcode rotation ios5 ios6
source share
1 answer

If you have a navigation controller that manages these views, the shouldAutorotate method will not be called. You must subclass the UINavigationController and override the shouldAutorotate and supportedIntervalOrientations methods.

From the docs:

Now iOS containers (e.g. UINavigationController) will not consult their children to determine if they should autorotate

Change -----

As mentioned below by Lomax, a subclass of UINavigationController is not recommended by Apple. Instead, you should try a category ( this SO question explains this well ):

 @implementation UINavigationController -(BOOL)shouldAutorotate { // your code } -(NSUInteger)supportedInterfaceOrientations { (...) } @end 
+3
source share

All Articles