开发者

How to hide UITabBarController programmatically?

开发者 https://www.devze.com 2022-12-19 21:36 出处:网络
Is it possible to hide it with animatio开发者_运维问答n ?A UITabBar inherits from UIView, so you can hide it and animate it like you would with a standard UIView.

Is it possible to hide it with animatio开发者_运维问答n ?


A UITabBar inherits from UIView, so you can hide it and animate it like you would with a standard UIView.

- (void) hideTheTabBarWithAnimation:(BOOL) withAnimation {
    if (NO == withAnimation) {
        [theTabBar setHidden:YES];
    } else {
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDelegate:nil];
        [UIView setAnimationDuration:0.75];

        [theTabBar setAlpha:0.0];       

        [UIView commitAnimations];
    }
}


You should use this code:

self.tabBarController.tabBar.hidden=YES;


You can also hide it using the attributes inspector:

How to hide UITabBarController programmatically?

but not with an animation.


-(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
hope this helps


Another Solution I use: Call Methods When You Want to Hide Menu:

//Show Tab Bar
[self showTabBar:self.tabBarController];
//If You Want to Hide/Show Navigation Bar Also
[self.navigationController setNavigationBarHidden: NO animated:YES];

//Hide Tab Bar
[self hideTabBar:self.tabBarController];  
//If You Want to Hide/Show Navigation Bar Also
[self.navigationController setNavigationBarHidden: YES animated:YES];

Methods:

- (void)hideTabBar:(UITabBarController *) tabbarcontroller
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];

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];
}

- (void)showTabBar:(UITabBarController *) tabbarcontroller
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];

for(UIView *view in tabbarcontroller.view.subviews)
{
    if([view isKindOfClass:[UITabBar class]])
    {
      [view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width,    
      view.frame.size.height)];

    }
    else
    {
      [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y,  
      view.frame.size.width, 431)];
     }
}

[UIView commitAnimations];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消