Question

I have a UIViewController inside Tab bar. For one VC in Tab bar I allow the interface to rotate upon device rotation. The challenge is, that I want to hide the Tab bar and resize my view inside.

What I did:

1) called - (void)willAnimateRotation.... in my Tab bar controller and set self.tabBar.isHidden to true -> the Tab bar disappeared.

2) called - (void)willAnimateRotation.... and set self.mapView.frame to maximum height.

BUT...I still have a black stripe in the bottom of the screen in exact size of the tab bar. Is there a way how to make the tab bar disappeat completely?

Was it helpful?

Solution

[self hideTabBar:self.tabBarController];


- (void) hideTabBar:(UITabBarController *) tabbarcontroller {

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    for(UIView *view in tabbarcontroller.view.subviews)
    {
        if([view isKindOfClass:[UITabBar class]])
        {
            [view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
        } 
        else 
        {
            [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
        }

    }
    [UIView commitAnimations];    
}

OTHER TIPS

This worked for me

- (void)viewDidLoad {
    [super viewDidLoad];    
    previousRect = self.view.frame;     
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
{
    if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {               
        [self.navigationController setNavigationBarHidden:TRUE animated:FALSE]; 
        [[UIApplication sharedApplication] setStatusBarHidden:TRUE animated:FALSE];
    }
    else
    {
        [self.navigationController setNavigationBarHidden:FALSE animated:FALSE];
        [[UIApplication sharedApplication] setStatusBarHidden:FALSE animated:FALSE];
    }
}

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
    UIInterfaceOrientation toOrientation = self.interfaceOrientation;

    if ( self.tabBarController.view.subviews.count >= 2 )
    {
        UIView *transView = [self.tabBarController.view.subviews objectAtIndex:0];
        UIView *tabBar = [self.tabBarController.view.subviews objectAtIndex:1];

        if(toOrientation == UIInterfaceOrientationLandscapeLeft || toOrientation == UIInterfaceOrientationLandscapeRight) {                                     
                transView.frame = CGRectMake(0, 0, 480, 320 );
                tabBar.hidden = TRUE;
        }
        else
        {                               
                transView.frame = previousRect;         
                tabBar.hidden = FALSE;
        }
    }
}

If you want to always hide the tab bar when a particular UIViewController is pushed, you can do:

self.hidesBottomBarWhenPushed = YES;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top