Change views with orientation

Discussion in 'iOS Programming' started by john903, Sep 20, 2008.

  1. john903 macrumors member

    Joined:
    Apr 11, 2008
    #1
    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!
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    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...
     
  3. john903 thread starter macrumors member

    Joined:
    Apr 11, 2008
    #3
    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.
     
  4. mccannmarc macrumors 6502

    mccannmarc

    Joined:
    Aug 15, 2008
    Location:
    Manchester, UK

Share This Page