How to hide tab bar programmatically and then expand view to fit

前端 未结 5 649
余生分开走
余生分开走 2021-01-15 11:39

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

相关标签:
5条回答
  • 2021-01-15 11:49

    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.

    0 讨论(0)
  • 2021-01-15 11:55

    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)];
        }
    }
    
    0 讨论(0)
  • 2021-01-15 11:55

    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];
    
    0 讨论(0)
  • 2021-01-15 12:07
    -(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
    
    0 讨论(0)
  • 2021-01-15 12:10

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

    0 讨论(0)
提交回复
热议问题