views:

31

answers:

1

Hello, 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?

A: 

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] http://stackoverflow.com/questions/402/iphone-app-in-landscape-mode

Kalle