2010-02-13 14 views

Odpowiedz

22

UITabBar dziedziczy z UIView, dzięki czemu można go ukryć i animować tak, jak przy standardowym 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

Dzięki za twoją radę Guillaume – RAGOpoR

+0

Jesteś welc ome. Chętnie pomogę :) – Guillaume

+0

Sprawili, że mój dzień! <3 –

20

Należy użyć tego kodu:

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

ładna porada dzięki – lomec

+0

Dziękujemy! Proste i dobrze zrobione. – Felipe

+1

Zostawia mi miejsce zamiast czarnego paska ... Nie jest to dobre rozwiązanie – Flupp

5

Można również ukryć za pomocą Inspektora atrybuty:

enter image description here

ale nie z animacją.

+0

To jest proste i doskonałe –

0

Innym rozwiązaniem używam: Metody połączenia Gdy chcesz ukryć 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]; 

metod:

- (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 
Powiązane problemy