欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

iphone开发如何隐藏各种bar

发布时间:2023/11/30 51 豆豆
生活随笔 收集整理的这篇文章主要介绍了 iphone开发如何隐藏各种bar 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

转载至:http://blog.csdn.net/riveram/article/details/7291142

状态条StatusBar

[cpp] view plaincopyprint?
  • [UIApplication sharedApplication].statusBarHidden = YES;  
  • [UIApplication sharedApplication].statusBarHidden = YES;

     导航条NavigationBar

    [cpp] view plaincopyprint?
  • [self.navigationController setNavigationBarHidden:YES];  
  • [self.navigationController setNavigationBarHidden:YES];


    TabBar

    方法1

    [cpp] view plaincopyprint?
  • [self.tabBarController.tabBar setHidden:YES];  
  • [self.tabBarController.tabBar setHidden:YES];


    这个方法有问题,虽然tabBar被隐藏了,但是那片区域变成了一片空白,无法被其他视图使用。

    方法2

    对于navigationController+tabBarController的结构,可以在push下一级的childController之前将childController的hidesBottomBarWhenPushed属性设为YES。

    比如,可以在childController的初始化方法中做这件事,代码如下:

    [cpp] view plaincopyprint?
  • // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.  
  •    
  •  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {  
  •      self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];  
  •      if (self) {  
  •          // Custom initialization.  
  •          self.hidesBottomBarWhenPushed = YES;  
  •      }  
  •      return self;  
  •  }  
  • // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];if (self) {// Custom initialization.self.hidesBottomBarWhenPushed = YES;}return self;}

    方法3

    [cpp] view plaincopyprint?
  • - (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;  
  •      //    [UIView commitAnimations];     
  •  }  
  • - (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;// [UIView commitAnimations]; }



    时机

    [cpp] view plaincopyprint?
  • - (void)viewWillAppear:(BOOL)animated {  
  •      [self setFullScreen:YES];  
  •  }  
  •    
  •  - (void)viewWillDisappear:(BOOL)animated {  
  •      [self setFullScreen:NO];  
  •  }  
  •    
  •  - (void)setFullScreen:(BOOL)fullScreen {  
  •      // 状态条   
  •      [UIApplication sharedApplication].statusBarHidden = fullScreen;  
  •      // 导航条   
  •      [self.navigationController setNavigationBarHidden:fullScreen];  
  •      // tabBar的隐藏通过在初始化方法中设置hidesBottomBarWhenPushed属性来实现。  
  •  }  
  • - (void)viewWillAppear:(BOOL)animated {[self setFullScreen:YES];}- (void)viewWillDisappear:(BOOL)animated {[self setFullScreen:NO];}- (void)setFullScreen:(BOOL)fullScreen {// 状态条[UIApplication sharedApplication].statusBarHidden = fullScreen;// 导航条[self.navigationController setNavigationBarHidden:fullScreen];// tabBar的隐藏通过在初始化方法中设置hidesBottomBarWhenPushed属性来实现。}


    总结

    以上是生活随笔为你收集整理的iphone开发如何隐藏各种bar的全部内容,希望文章能够帮你解决所遇到的问题。

    如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。