2

I got the code from this question: How to hide UITabBarController programmatically? which is brilliant, however the view doesn't expand to fit the space left by the tab bar now.

I have set the appropriate UIViewAutoresizingMasks to the view, but I'm assuming that just because its hidden doesn't mean its not still taking up the space?

Anyway, if I do [self.navigationController setNavigationBarHidden:YES animated:YES]; then the navigation bar moves up and off the screen expanding the view with it.

How can I replicate this behavior for the Tab Bar?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Thomas Clayson
  • 29,657
  • 26
  • 147
  • 224

5 Answers5

1

This worked great for me! (combines solutions from other posts mentioned -580 is randomly large number)

for(UIView *view in self.tabBarController.view.subviews)
{
    if([view isKindOfClass:[UITabBar class]])
    {
        [view setFrame:CGRectMake(view.frame.origin.x, 580, view.frame.size.width,            
                                  view.frame.size.height)];
    }
    else
    {
        [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y,        
                                  view.frame.size.width, view.frame.size.height +40)];
    }
}
juggler
  • 319
  • 1
  • 5
  • 16
1
-(void)hideTabBar
{   UITabBarController * tabbarcontroller= appDelegate.tabBarVC;
        if (tabbarcontroller.tabBar.isHidden) 
    {
        return;
    }
    tabbarcontroller.tabBar.hidden=YES;
    CGRect frm=tabbarcontroller.view.frame;
    frm.size.height += tabbarcontroller.tabBar.frame.size.height;
    tabbarcontroller.view.frame=frm;
}
-(void)showTabBar
{    UITabBarController * tabbarcontroller=appDelegate.tabBarVC;
    if (!tabbarcontroller.tabBar.isHidden)
    {
        return;
    }
    CGRect frm=tabbarcontroller.view.frame;
    frm.size.height -= tabbarcontroller.tabBar.frame.size.height;
    tabbarcontroller.view.frame=frm;
    tabbarcontroller.tabBar.hidden=NO;  
}
here appDelegate is = (AppDelegate *) [[UIApplication sharedApplication] delegate]
tabBarVc is UITabBarController *tabBarVC defined as property in app delegate
Tanuj Jagoori
  • 309
  • 3
  • 9
1

Turns out its not quite possible. Best way is to present a modal view (navigation) controller instead of pushing a view controller.

Thomas Clayson
  • 29,657
  • 26
  • 147
  • 224
0

in NSContraints era, do NOT try to modify frame by code, bad things may happen.

Use: pushedViewController.hidesBottomBarWhenPushed = YES;

typically set hidesBottomBarWhenPushed to yes in prepareforSegue, ANYWAY before iOS actually pushes the new controller.

ingconti
  • 10,876
  • 3
  • 61
  • 48
-1

The easiest way is probably to set a new frame for the view:

CGRect viewFrame = view.frame;
viewFrame.size.height += 40; // Change this to the height of the tab bar
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.75];

view.frame = viewFrame;

[UIView commitAnimations];
loomer
  • 2,017
  • 1
  • 17
  • 11
  • Theres just a white space at the bottom where the tab bar used to be. `self.view` has a background picture that doesn't move down and fill in where the tab bar used to be. – Thomas Clayson Oct 28 '10 at 08:03
  • Ok. Which view is you trying to set a new frame on? It probably doesn't work to change the frame of the view controller view, you need to add a subview. If you can post some code it would make it easier to answer your question. – loomer Oct 28 '10 at 08:27
  • I have viewController. self.view.backgroundColor is set to redColor and when I move the tabBarController the red color stops where the top of the tab bar used to be. :( Don't worry I've worked around it. Thanks for your help though. – Thomas Clayson Nov 01 '10 at 09:13