2010-02-13 123 views

回答

22

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

感謝您的建議Guillaume – RAGOpoR 2010-02-13 13:19:14

+0

You are welc青梅。很高興幫助:) – Guillaume 2010-02-13 14:13:31

+0

讓我的一天! <3 – 2012-03-22 16:33:04

20

您應使用此代碼:

self.tabBarController.tabBar.hidden=YES; 
+0

不錯的提示謝謝 – lomec 2013-02-21 17:06:13

+0

謝謝!簡單,做得好。 – Felipe 2016-04-15 22:47:11

+1

它爲我留下一個黑色空間代替標籤欄...不是一個好的解決方案 – Flupp 2016-08-06 20:16:25

5

您也可以使用屬性檢查器中隱藏:

enter image description here

但與動畫。

+0

這是簡單和完美的 – 2013-12-17 10:32:54

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]; 
} 
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 
hope this helps 
相關問題