IOS 6 - (BOOL) shouldAutorotate not getting a call for navigation controllers pushed by viewControllers

There is a navgationController for my rootViewController application.

I found that the pushed controller

-(BOOL)shouldAutorotate not called.

and

-(NSUInteger)supportedInterfaceOrientations is called only once.

I correctly checked the project summary (or plist ) in xcode's to support all window orientations.

I want this method to be called, since there is some uicontrol positioning code that I want to execute programmatically to change the orientation.

I solved this problem by overriding the (category) navigation controller with the following methods

 -(BOOL)shouldAutorotate; -(NSUInteger)supportedInterfaceOrientations; 

I checked which controller is pressed and, accordingly, called the corresponding pushed positioning code of the uicontrol controller in the navigation controller, following the method

 (NSUInteger)supportedInterfaceOrientations; 

This works fine, but I don't think this is the right way. Please help me for a better solution.

+7
source share
5 answers

You can check the following link, you need to create a custom navigation for support, which should rotate automatically

http://mobileappdevpage.blogspot.in/2012/11/how-to-use-should-autorotateios-6-with.html

Another way to do this is by creating the UINaviagationController category

code for the .h file

 @interface UINavigationController (autorotation) -(BOOL)shouldAutorotate; -(NSUInteger)supportedInterfaceOrientations; 

and code for the .m file

 @implementation UINavigationController (autorotation) -(BOOL)shouldAutorotate { UIInterfaceOrientation interfaceOrientation = [UIApplication sharedApplication].statusBarOrientation; [self.topViewController shouldAutorotate]; return YES; } -(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAll; } @end 
+27
source

I also ran into the same issue with the navigation controller. It works great for all pushed view controllers, but my scenario was completely different. I had one view manager connected to the navigation controller (ViewControllerParent) as the root,

 NavController -- rootViewController (ViewControllerParent) --- ViewControllerChild1 --- ViewControllerChild2 

Due to some project requirements, I supported ViewControllerParent as a base, and then added the Childviewcontroller view as child elements for the parent based on user actions. Now I had a scenario where I wanted Child1 to not spin and Child2 to spin.

The problem I ran into was that my [self.topViewController] in the navigation controller class always returns me the parent object, since I don't push Childs on the nav stack. Therefore, my toAutorotate methods in my Childs will never be called. So I had to put a class check in my parent's shouldAutorotate method, and then return the rotation value. I did something similar in the parent class (ViewControllerParent), this is kind of a workaround, but it fixed the problem

 -(BOOL)shouldAutorotate { BOOL allowRotation = YES; if ([currentlyLoadedChild isKindOfClass:[Child1 class]]) { allowRotation = NO; } if ([currentlyLoadedChild isKindOfClass:[Child2 class]]) { allowRotation = YES; } return allowRotation; } 

-anoop

+1
source

You can check the orientation of the interface with

 [UIApplication sharedApplication].statusBarOrientation 

when the view controller is loaded, say, in viewWillAppear . There you can make your layout subviews. When the browse is complete, shouldAutorotate will be called whenever the device is rotated.

0
source

Overriding the UINavigationController is the right approach, but I'm not sure if you control the pushInterfaceOrientations controllers correctly.

Take a look at my answer here: https://stackoverflow.com/a/316618/

0
source

I had the same problem. check this answer its great endorsement and not the application ShouldAutoRotate

0
source

All Articles