zoukankan      html  css  js  c++  java
  • iOS--隐藏和显示TabBar的方法

    1.隐藏TabBar:

    [cpp] view plain copy
    1. - (void)hideTabBar {  
    2.     if (self.tabBarController.tabBar.hidden == YES) {  
    3.         return;  
    4.     }  
    5.     UIView *contentView;  
    6.     if ( [[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] )  
    7.         contentView = [self.tabBarController.view.subviews objectAtIndex:1];  
    8.     else  
    9.         contentView = [self.tabBarController.view.subviews objectAtIndex:0];  
    10.     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);          
    11.     self.tabBarController.tabBar.hidden = YES;  
    12.       
    13. }  

    如果是在push之后的页面调用隐藏, 前一个页面要在willAppear中调用显示, 不然前一个页面的tabbar会消失掉. 


    2.显示TabBar:

    [cpp] view plain copy
    1. - (void)showTabBar  
    2.   
    3. {  
    4.     if (self.tabBarController.tabBar.hidden == NO)  
    5.     {  
    6.         return;  
    7.     }  
    8.     UIView *contentView;  
    9.     if ([[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]])  
    10.           
    11.         contentView = [self.tabBarController.view.subviews objectAtIndex:1];  
    12.   
    13.     else  
    14.           
    15.         contentView = [self.tabBarController.view.subviews objectAtIndex:0];        
    16.     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);  
    17.     self.tabBarController.tabBar.hidden = NO;  
    18.       
    19. }  


    3.如果定义了上面两个方法,在viewDidAppear:方法里面就可以调用了

    [cpp] view plain copy
      1. -(void)viewDidAppear:(BOOL)animated{  
      2.     //[self hideTabBar];  
      3.     [self showTabBar];  
      4. }  
  • 相关阅读:
    这是一个包括189819个字母的肌联蛋白的化学名
    開始Unity3D的学习之旅
    scanf函数
    Android应用中使用百度地图API并加入标注(一)
    android 5.0新特性
    高速阅读
    GitHub具体教程
    十一招解决:系统IE部分网页打不开怎么办(转载)
    c语言中的位移位操作
    [置顶] android调用第三方库——第四篇——调用多个第三方库
  • 原文地址:https://www.cnblogs.com/mafeng/p/5858148.html
Copyright © 2011-2022 走看看