1

I have a UITabBar based iOS application with 5 tabs, some of these tabs are UINavigationControllers. Some of my tab views support landscape while others do not.

I have all of the auto-rotation taken care of for the views themselves, but I noticed something peculiar happening when I was testing the app - whenever a new tab is selected, the shouldAutoRotateToInterfaceOrientation method is not called by any UIViewController. Is there any way to force an orientation check upon selecting a new tab?

Daniel
  • 23,129
  • 12
  • 109
  • 154
Maximilian
  • 23
  • 2
  • 6
  • You said "auto-rotation taken care of for the views themselves", but you mean in the view controllers, right? Do you have a `UITabBar` or a `UITabBarViewController`? – DBD Sep 05 '12 at 18:10

5 Answers5

1

Create a method and call it in viewWillAppear to check orientation and then force it if need be.

Daniel
  • 23,129
  • 12
  • 109
  • 154
Derick F
  • 2,749
  • 3
  • 20
  • 30
  • Do you have an example of such a method? As far as I know, there is no method in the SDK for forcing an orientation change (I believe it's a private function call, and Apple won't allow it in published apps). – Maximilian Aug 10 '12 at 14:17
  • if ([[UIApplication sharedApplication] statusBarOrientation] != UIDeviceOrientationLandscapeLeft) { // setup status bar [[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationLandscapeLeft animated:NO]; } [link to full example](http://stackoverflow.com/a/4850531/1190203) – Derick F Aug 11 '12 at 08:08
0

Usually when I see this it is because one of the viewcontrollers in the tabbar does not have the shouldAutoRotateToInterfaceOrientation set properly. All of the classes added to the tabbar need to have the same value set or it will trip up the rotation.

Daniel
  • 23,129
  • 12
  • 109
  • 154
dnstevenson
  • 697
  • 7
  • 16
  • All of the view controllers in the tab bar controller implement shouldAutoRotateToInterfaceOrientation, but the method is never called. – Maximilian Aug 10 '12 at 14:14
0

The method shouldAutorotateToInterfaceOrientation: is NOT supported in iOS 6. Its deprecated. Just in case if you are a newbie, who just stared working in cocoa, and wondering why is your view controller messed up in iOS 6 and perfect in iOS 5, just know that shouldAutorotateToInterfaceOrientation: is not supported anymore. Even though it may work well with Xcode 4 to 4.3 it will NOT work on Xcode 4.5.

Apple provides a new method to get this thing done, in a much cleaner fashion. You use supportedInterfaceOrientations instead. It returns all of the interface orientations that the view controller supports, a mask of interface orientation values.

UIInterfaceOrientationMask Enum:

These constants are mask bits for specifying a view controller’s supported interface orientations.

    typedef enum {
     UIInterfaceOrientationMaskPortrait = (1 << UIInterfaceOrientationPortrait),
     UIInterfaceOrientationMaskLandscapeLeft = (1 << UIInterfaceOrientationLandscapeLeft),
     UIInterfaceOrientationMaskLandscapeRight = (1 << UIInterfaceOrientationLandscapeRight),
     UIInterfaceOrientationMaskPortraitUpsideDown = (1 << UIInterfaceOrientationPortraitUpsideDown),
     UIInterfaceOrientationMaskLandscape =
     (UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight),
     UIInterfaceOrientationMaskAll =
     (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |
     UIInterfaceOrientationMaskLandscapeRight | UIInterfaceOrientationMaskPortraitUpsideDown),
     UIInterfaceOrientationMaskAllButUpsideDown =
     (UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscapeLeft |
     UIInterfaceOrientationMaskLandscapeRight),
 } UIInterfaceOrientationMask;
PVitt
  • 11,500
  • 5
  • 51
  • 85
Ignacio Barrea
  • 121
  • 2
  • 5
0

The Apple UIViewController Programming Guide for iOS states:

"the tab bar controller allows orientation changes only if all of its managed view controllers support the new orientation."

If you want to support landscape then you need to make sure all tabs support it, as it's a case of all or nothing.

ader
  • 5,403
  • 1
  • 21
  • 26
0

May be u using ios 6.0 or above, As in ios 6.0 and above shouldAutoRotateToInterfaceOrientation method is being depreceted and is not called for this u have to create own categories for both UINavigationController and UITabbarContrller and add some methods for being called when device rotates.

vishwa.deepak
  • 510
  • 4
  • 18