UITabBarController rotation issues in ios 6

Ack! I had tab rotation problems that were finally resolved in iOS 5, but iOS 6 and xcode seem to have broken things ... this is what I have:

Target information about the application includes: Supported interface orientations - Portraits, Landscape on the left, Landscape on the right

Each Single View in the application has the following methods:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { return ((interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown) && (interfaceOrientation != UIInterfaceOrientationLandscapeLeft) && (interfaceOrientation != UIInterfaceOrientationLandscapeRight)); } else { return YES; } } - (BOOL)shouldAutorotate { NSLog(@"am I called1?"); return NO; } -(NSUInteger)supportedInterfaceOrientations{ NSLog(@"am I called?"); return UIInterfaceOrientationMaskPortrait; } 

In views that are not part of the tab bar, rotation is blocked. In ALL views on the tab (there are 5), the application never calls ShouldAutorotate and therefore rotates. It seems to be supported .InterfaceOrientations is called once when the view is loaded, but not when it appears if I switch between the views because I get an NSLog, but it seems to ignore the MaskPortrait parameter.

I need to leave the landscape included in the target, because I have one view of the video player that needs to be rotated (and it does it, great)

Is this a tab error in iOS 6? Do I need to turn off the rotation of views in different ways? Orientation worked fine in authorized interface in ios 5

I was on it for a while

Thanks Zack

+16
objective-c rotation ios6 uitabbarcontroller
Sep 21
source share
8 answers

Zack, I ran into this problem. This is because you have a viewController built-in inside the TabBar or UINavigationController, and calls to these methods occur inside them instead of the usual View (modified in iOS6).

I ran into this problem because I represented the viewController built-in inside the UINavigationController in all of my modal views in which there was Navigation for different views (registration process, login, etc.).

My simple fix was to create a CATEGORY for the UINavigationController that includes these two methods. I need Autorotate to return NO, because I don't want my modal views to rotate. Your fix may be so simple, try it. Hope this helps.

I created a category and named it autoRotate and selected the UINavigationController option. The M + H file is located below.

 #import "UINavigationController+autoRotate.h" @implementation UINavigationController (autoRotate) -(BOOL)shouldAutorotate { return NO; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } @end 

... and category .h:

 #import <UIKit/UIKit.h> @interface UINavigationController (autoRotate) -(BOOL)shouldAutorotate; - (NSUInteger)supportedInterfaceOrientations; @end 
+36
Sep 21 '12 at 7:37
source share

If you have a tab bar like me, the only thing you need to do is add the following to the delegate .m file,

 #import "AppDelegate.h" //UITabBarController category to set the view rotations for ios 6 @implementation UITabBarController (Background) -(BOOL)shouldAutorotate { //I don't want to support auto rotate, but you can return any value you want here return NO; } - (NSUInteger)supportedInterfaceOrientations { //I want to only support portrait mode return UIInterfaceOrientationMaskPortrait; } @end /////here starts the implementation of the app delegate which is gonna be whatever you currently have on your .m delegate @implementation AppDelegate // delegate methods and other stuff @end 
+11
Oct 31 '12 at 22:05
source share

I also had a problem in that I needed some views for rotation, and others not with multiple navigation controllers. I did this by telling the navigation controller to look in the view controller. Here is what I did.

I create a UINavigationController class called RootNavigationController and have assigned this class as a custom class for navigation controllers in a storyboard. In RootNavigationController.m, I have added the following methods:

 - (BOOL)shouldAutorotate { return [self.visibleViewController shouldAutorotate]; } - (NSUInteger)supportedInterfaceOrientations { return [self.visibleViewController supportedInterfaceOrientations]; } 

In each controller .m file, I also added the following methods.

 - (BOOL)shouldAutorotate { //return yes or no } - (NSUInteger)supportedInterfaceOrientations{ //return supported orientation masks } 

This allows me to adjust the orientation for each view in my view controller.

Worked for me anyway ...

+7
Sep 25 '12 at 21:33
source share

My situation:

  • UITabBarController has 2 elements: 2 Navigation controller
  • UINavigationController1 withRootView: ViewController1
  • UINavigationController2 withRootView: ViewController2.
  • Now I want ViewController1 to set shouldAutorotate: NO / maskPortrait and ViewController2 set shouldAutorotate / MaskAll.

So my tool: Create a UITabBarController category and a UINavigationCntroller category, for example

UITabBarController + autoRotate.h

 @interface UITabBarController (autoRotate) -(BOOL)shouldAutorotate; - (NSUInteger)supportedInterfaceOrientations; @end 

UITabBarController + autoRotate.m

 #import "UITabBarController+autoRotate.h" @implementation UITabBarController (autoRotate) - (BOOL)shouldAutorotate { return [self.selectedViewController shouldAutorotate]; } - (NSUInteger)supportedInterfaceOrientations { return [self.selectedViewController supportedInterfaceOrientations]; } @end 

UINavigationController + autoRotate.h

 @interface UINavigationController (autoRotate) -(BOOL)shouldAutorotate; - (NSUInteger)supportedInterfaceOrientations; @end 

UINavigationController + autoRotate.m

 @implementation UINavigationController (autoRotate) - (BOOL)shouldAutorotate { return [self.visibleViewController shouldAutorotate]; } - (NSUInteger)supportedInterfaceOrientations { return [self.visibleViewController supportedInterfaceOrientations]; } @end 

UIViewController1.m

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

UIViewController2.m

 - (BOOL)shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAll; } 

It worked like a charm!

+6
Jun 18 '13 at 6:22
source share

In my case, I had a navigation controller built into the UITabBarController, and what worked created a category like Kunani, but extended the UITabBarController instead of the UINavigationController. It worked like a charm :)

 #import "UINavigationController+autoRotate.h" @implementation UINavigationController (autoRotate) -(BOOL)shouldAutorotate { return NO; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait; } @end 

And the .h file:

 #import <UIKit/UIKit.h> @interface UINavigationController (autoRotate) -(BOOL)shouldAutorotate; - (NSUInteger)supportedInterfaceOrientations; @end 
0
Jun 13 '13 at 21:52
source share

It will be done in Swift

 extension UITabBarController { public override func shouldAutorotate() -> Bool { if let selected = self.selectedViewController { return selected.shouldAutorotate() } else { return false } } public override func supportedInterfaceOrientations() -> Int { if let selected = self.selectedViewController { return selected.supportedInterfaceOrientations() } else { return Int(UIInterfaceOrientationMask.Portrait.rawValue) } } } extension UINavigationController { public override func shouldAutorotate() -> Bool { return self.visibleViewController.shouldAutorotate() } public override func supportedInterfaceOrientations() -> Int { return self.visibleViewController.supportedInterfaceOrientations() } } 
0
Dec 11 '14 at 11:48
source share

stack overflow

when handling this situation, many ambiguous or unanticipated results arise, especially when it comes to maintaining orientation only for a certain view controller and not for the rest of the application. this algorithm seems to hand me everything

stack overflow

0
Jun 03 '15 at 23:28
source share

You must add this thing to UIViewController1.m to ensure that the previous orientation status is restored:

  (void)viewDidAppear:(BOOL)animated { [[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:") withObject:(id)UIInterfaceOrientationPortrait]; } 

Perfect!

-one
Jun 18 '13 at 7:36 on
source share



All Articles