1

I have a tab bar application in which i have 3 diffrent views each with there own view controller.

In the tab bar code i have this, to handle rotation.

#import "RotatingTabBarController.h"

@implementation RotatingTabBarController

    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

      return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation]; 
 }
@end

Then in the 2nd view controller that i want to rotate depending on device orientation i have:

// Override to allow orientations other than the default portrait orientation.
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

   return YES;
 }

And For the other two views that i do not want to rotate i have this method set.

// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 // Return YES for supported orientations
 return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

The PROBLEM: so this works fine in view 1 and view 3 when u rotate the device they stay in portrait mode which is desired. When in view 2 i rotate to landscape, the view does as expected and rotates to landscape. BUT when click view 1 or view 3 tab while in lanscape mode in view 2, View 1 and View 3 are in landscape mode.

I can't figure out how to force them in portrait even if view 2 rotates to lanscape.

Any one know how to do this?

Matt
  • 2,803
  • 9
  • 33
  • 57

1 Answers1

1

There's a big discussion[1] on this dating back from 2008 until now (look at comments down a few pages) -- summarily it seems like

application.statusBarOrientation = UIInterfaceOrientationLandscapeRight;

or

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

or

[application setStatusBarOrientation: UIInterfaceOrientationLandscapeRight animated:NO];

will let you force it to landscape -- you would want to do this when the user goes back to your landscapey view(s) programmatically.

[1] iPhone app in landscape mode, 2008 systems

Community
  • 1
  • 1
Kalle
  • 13,186
  • 7
  • 61
  • 76
  • This shouldn't really be used at any time apart from app launch. Forcing a status bar orientation mid-way through the application lifecycle is very bad and can have unintended consequences. – Benjamin Mayo Jun 24 '12 at 23:06
  • Any official sources saying that? There are apps which have e.g. a "view mode" which switches orientation if necessary, and a bunch of other cases where an orientation change is necessary. – Kalle Jun 25 '12 at 13:14
  • "If your application has rotatable window content, however, you should not arbitrarily set status-bar orientation using this method" - http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIApplication_Class/Reference/Reference.html – Benjamin Mayo Jun 25 '12 at 18:27