如何通过编程方式隐藏UITabBarController?

时间:2010-02-13 10:32:00

标签: iphone uitabbarcontroller

是否可以用动画隐藏它?

5 个答案:

答案 0 :(得分:23)

UITabBar继承自UIView,因此您可以像使用标准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];
    }
}

答案 1 :(得分:23)

您应该使用以下代码:

self.tabBarController.tabBar.hidden=YES;

答案 2 :(得分:6)

您也可以使用属性检查器隐藏它:

enter image description here

但没有动画。

答案 3 :(得分:2)

-(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

答案 4 :(得分:0)

我使用的另一个解决方案: 当您想要隐藏菜单时调用方法:

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

方法:

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