Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems with Interface Orientation and UITabBarController

Quick problem:

I have an UITabBarController with 2 navigation controllers [lets call them Left and Right Controller]

On the default selected Left Controller I can push a new View Controller that detects interface orientation.

On the Right Controller I can push the same View Controller but it won't detect interface orientation, or for that matter, It won't even go into the shouldAutoRotateInterface method at all T___T

Haaalp!!

If it is of any relevance, the View Contoller that I'm pushing use the hidesBottomBarWhenPushed property.

like image 873
Ayton McLoving Avatar asked Nov 22 '25 09:11

Ayton McLoving


2 Answers

Most likely this is your problem:

Tab bar controllers support a portrait orientation by default and do not rotate to a landscape orientation unless all of the root view controllers support such an orientation. When a device orientation change occurs, the tab bar controller queries its array of view controllers. If any one of them does not support the orientation, the tab bar controller does not change its orientation.

The solution is to override the following method on every view controller leading to your view:

- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orientation {
    return YES;
}

For example, instead using the default UITabBarController in IB, replace it with your own subclass containing just the method above.

like image 162
Jano Avatar answered Nov 24 '25 21:11

Jano


I'm a bit late to the party on this, but I ran into a problem with autorotation at startup for a tab bar app I wanted always to run in portrait.

The app's plist has the necessary settings to both start in and only allow portrait mode, and all my view controllers only allow portrait mode. Yet, when I started the app holding my iPhone in landscape, the app started in portrait, but then rotated to landscape!

Rather than subclass UITabBarController, I simply overrode UITabBarController's shouldAutorotateToInterfaceOrientation: method using a category on class UITabBarController. I included this code in my app delegate:

@implementation UITabBarController(UITabBarControllerCategory)

-(BOOL)shouldAutorotateToInterfaceOrientation:
                 (UIInterfaceOrientation)toInterfaceOrientation
{
    return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

Works beautifully, and is quite lightweight.

like image 40
Mark Granoff Avatar answered Nov 24 '25 21:11

Mark Granoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!