IO6 does not call - (BOOL) shouldAutorotate

I have some insights in my application that I do not want to maintain orientation. In didFinishLaunchingWithOptions I add navigation:

 ... UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:self.viewController]; self.window.rootViewController = nav; [self.window makeKeyAndVisible]; ... 

In every ViewController I have a UITabBar (I don't know if this is important).

In the first view of the controller, I add:

 -(BOOL)shouldAutorotate { return NO; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } 

supportedInterfaceOrientations is called when the view loads, but shouldAutorotate does not call when I rotate the device.
What am I missing here?

+2
ios objective-c iphone ios6 uiinterfaceorientation
October 21
source share
2 answers

This is because neither the UITabBarcontroller nor the UINavigationController passes the shouldAutorotate to its visible view controller. To fix this, you can subclass either UITabBarController or UINavigationController and forward shouldAutorotate from there:

In your subclass of UITabBarController add:

 - (BOOL)shouldAutorotate { return [self.selectedViewController shouldAutorotate]; } 

In your subclass of UINavigationController add:

 - (BOOL)shouldAutorotate { return [self.visibleViewController shouldAutorotate]; } 
+15
Oct 21 '12 at 10:13
source share
— -

in AppDelegate :

 - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window // iOS 6 { return UIInterfaceOrientationMaskAll; } 

in your ViewController:

 - (BOOL)shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } 
0
Oct. 21
source share



All Articles