Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

john903

macrumors member
Original poster
Apr 11, 2008
66
0
I have a UITabBarController that I want to show in portrait orientation and a UIViewController to show when in landscape orientation.

I add both controller's view to the window.
Code:
[window addSubview:viewController.view];
[window addSubview:tabBarController.view];

I have the shouldAutorotateToInterfaceOrientation method like this for each controller.
Code:
// UITabBarController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
	return interfaceOrientation == UIInterfaceOrientationPortrait;
}

// UIViewController
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
	if(interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
	{
		return NO;
	}
	else if(interfaceOrientation == UIInterfaceOrientationPortrait)
	{
		[window bringSubviewToFront:[tabBarController view]];
		return NO;
	}

	// landscape
	[window bringSubviewToFront:[self view]];
	return YES;
}

This works great but the status bar always stays in landscape mode after the first rotation to landscape. When returning to portrait the UITabBarController will display properly but the status bar will not be returned to the right position.

Thanks for the help! If there is a better way to do this please let me know!
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
I'm pretty sure you need to return YES where UIInterfaceOrientationPortrait. If you return NO you are saying that you do not support this orientation so the status bar stays where it is...
 

john903

macrumors member
Original poster
Apr 11, 2008
66
0
I put no because I want the view controller to only ever be in landscape mode. Selecting Yes will actually fix the issue, but then it takes extra time to rotate the view when it doesn't need to since I show the tab controller in portrait mode.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.