iOS 隱藏tabBar小結(jié)

1

iOS跳轉(zhuǎn)界面時(shí)隱藏tabBar的方法

//1.設(shè)置self.tabBarController.tabBar.hidden=YES;
     
    self.tabBarController.tabBar.hidden=YES;
 
//2.如果在push跳轉(zhuǎn)時(shí)需要隱藏tabBar,設(shè)置self.hidesBottomBarWhenPushed=YES;
 
    self.hidesBottomBarWhenPushed=YES;
    NextViewController *next=[[NextViewController alloc]init];
    [self.navigationController pushViewController:next animated:YES];
    self.hidesBottomBarWhenPushed=NO;
 
//并在push后設(shè)置self.hidesBottomBarWhenPushed=NO;
//這樣back回來的時(shí)候,tabBar會(huì)恢復(fù)正常顯示。

2

Iphone隱藏和顯示TabBar的方法
1.隱藏TabBar:

- (void)hideTabBar {  
    if (self.tabBarController.tabBar.hidden == YES) {  
        return;  
    }  
    UIView *contentView;  
    if ( [[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] )  
        contentView = [self.tabBarController.view.subviews objectAtIndex:1];  
    else  
        contentView = [self.tabBarController.view.subviews objectAtIndex:0];  
    contentView.frame = CGRectMake(contentView.bounds.origin.x,  contentView.bounds.origin.y,  contentView.bounds.size.width, contentView.bounds.size.height + self.tabBarController.tabBar.frame.size.height);          
    self.tabBarController.tabBar.hidden = YES;  
      
}  

2.顯示TabBar:

- (void)showTabBar  
  
{  
    if (self.tabBarController.tabBar.hidden == NO)  
    {  
        return;  
    }  
    UIView *contentView;  
    if ([[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]])  
          
        contentView = [self.tabBarController.view.subviews objectAtIndex:1];  
  
    else  
          
        contentView = [self.tabBarController.view.subviews objectAtIndex:0];        
    contentView.frame = CGRectMake(contentView.bounds.origin.x, contentView.bounds.origin.y,  contentView.bounds.size.width, contentView.bounds.size.height - self.tabBarController.tabBar.frame.size.height);  
    self.tabBarController.tabBar.hidden = NO;  
      
}  

3.如果定義了上面兩個(gè)方法,在viewDidAppear:方法里面就可以調(diào)用了

-(void)viewDidAppear:(BOOL)animated{  
    //[self hideTabBar];  
    [self showTabBar];  
} 

3

iOS隱藏tabBar的方法

兩種方法用來隱藏tabBar
1.在本頁(yè)面隱藏
#pragma mark - 隱藏tabBar
- (void)viewWillAppear:(BOOL)animated{
   ** self.tabBarController.tabBar.hidden = YES;**
}
- (void)viewWillDisappear:(BOOL)animated{
**  self.tabBarController.tabBar.hidden = NO;**
}
2.再跳界面之前設(shè)置跳轉(zhuǎn)后隱藏tabBar
#pragma mark - 隱藏tabBar
- (void)handleClickTestButtonAction:(UIButton *)sender{
    SecurityTestingViewController *test = [[SecurityTestingViewController alloc]init];
    **self.hidesBottomBarWhenPushed = YES;**
    [self.navigationController pushViewController:test animated:NO];
}

4

隱藏TabBar的一些方法小結(jié)

//在項(xiàng)目中經(jīng)常遇到隱藏tabBar,實(shí)力很多種方法,可以解決不同情況下問題
//1://隱藏tabBar
    WebViewController *webVc = [[WebViewController alloc] init];
    webVc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:webVc animated:YES];
    webVc.hidesBottomBarWhenPushed = NO;
    [webVc release];
//2.系統(tǒng)方法
    self.hidesBottomBarWhenPushed = YES;
//3:自定義tabBar時(shí)候,由tabBarController管理的
//隱藏tabBar
- (void) hideTabBar:(BOOL) hidden{
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0];
    for(UIView *view in self.tabBarController.view.subviews)    {
        if ([view isKindOfClass:[UITabBar class]]) {
            if (hidden) {
                [view setFrame:CGRectMake(view.frame.origin.x, iphone5?568:480, view.frame.size.width, view.frame.size.height)];
            } else {
                [view setFrame:CGRectMake(view.frame.origin.x, iphone5?568-49:480-49, view.frame.size.width, view.frame.size.height)];
            }
        } else {
            if (hidden) {
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, iphone5?568:480)];
            } else {
                [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width,  iphone5?568-49:480-49)];
            }
        }
    }
    [UIView commitAnimations];
}
//調(diào)整子視圖
for (UIView *subView in self.view.subviews) {
    if ([subView isKindOfClass:NSClassFromString(@"UITransitionView")]) {
//        調(diào)整子視圖的高度,UITransitionView視圖為UINavitaionController的根視圖
        subView.frame = CGRectMake(subView.frame.origin.x, subView.frame.origin.y, subView.frame.size.width, 480);
        CGRect frame = subView.frame;
        frame.size.height = 480;
        subView.frame = frame;
    }
}
//4:類似方法3
- (void)makeTabBarHidden:(BOOL)hide{
    if ([self.tabBarController.view.subviews count] < 2)    {
        return;
    }
    UIView *contentView;
    if ([[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]])
    {
        contentView = [self.tabBarController.view.subviews objectAtIndex:1];
    }
    else
    {
        contentView = [self.tabBarController.view.subviews objectAtIndex:0];
    }
    //    [UIView beginAnimations:@"TabbarHide" context:nil];
    if (hide) {
        contentView.frame = self.tabBarController.view.bounds;
    }
    else
    {
        contentView.frame = CGRectMake(self.tabBarController.view.bounds.origin.x,
                                       self.tabBarController.view.bounds.origin.y,
                                       self.tabBarController.view.bounds.size.width,
                                       self.tabBarController.view.bounds.size.height - self.tabBarController.tabBar.frame.size.height);
    }       
    self.tabBarController.tabBar.hidden = hide;
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容