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

状态条StatusBar

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

 导航条NavigationBar

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

TabBar

方法1

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

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

方法2

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

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

[cpp] view plaincopyprint?
  1. // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
  2. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
  3. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  4. if (self) {
  5. // Custom initialization.
  6. self.hidesBottomBarWhenPushed = YES;
  7. }
  8. return self;
  9. }
// 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?
  1. - (void)makeTabBarHidden:(BOOL)hide
  2. {
  3. if ( [self.tabBarController.view.subviews count] < 2 )
  4. {
  5. return;
  6. }
  7. UIView *contentView;
  8. if ( [[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] )
  9. {
  10. contentView = [self.tabBarController.view.subviews objectAtIndex:1];
  11. }
  12. else
  13. {
  14. contentView = [self.tabBarController.view.subviews objectAtIndex:0];
  15. }
  16. //    [UIView beginAnimations:@"TabbarHide" context:nil];
  17. if ( hide )
  18. {
  19. contentView.frame = self.tabBarController.view.bounds;
  20. }
  21. else
  22. {
  23. contentView.frame = CGRectMake(self.tabBarController.view.bounds.origin.x,
  24. self.tabBarController.view.bounds.origin.y,
  25. self.tabBarController.view.bounds.size.width,
  26. self.tabBarController.view.bounds.size.height - self.tabBarController.tabBar.frame.size.height);
  27. }
  28. self.tabBarController.tabBar.hidden = hide;
  29. //    [UIView commitAnimations];
  30. }
- (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?
  1. - (void)viewWillAppear:(BOOL)animated {
  2. [self setFullScreen:YES];
  3. }
  4. - (void)viewWillDisappear:(BOOL)animated {
  5. [self setFullScreen:NO];
  6. }
  7. - (void)setFullScreen:(BOOL)fullScreen {
  8. // 状态条
  9. [UIApplication sharedApplication].statusBarHidden = fullScreen;
  10. // 导航条
  11. [self.navigationController setNavigationBarHidden:fullScreen];
  12. // tabBar的隐藏通过在初始化方法中设置hidesBottomBarWhenPushed属性来实现。
  13. }
- (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相关推荐

  1. iPhone开发中的一些小技巧

    NavBar+TarBar iphone开发 NavBar+TarBar 1  改变NavBar颜色:选中Navigation Bar 的Tint属性.选中颜色. 2  隐藏"back&qu ...

  2. iphone开发笔记和技巧总结

    在iphone程序中实现截屏的一种方法: //导入头文件   #importQuartzCore/QuartzCore.h //将整个self.view大小的图层形式创建一张图片imageUIGrap ...

  3. [IOS]iphone开发之常用代码:不断更新

    1,获取翻转事件,并开启翻转: 只要在viewcontroller的类中加入 -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOri ...

  4. iphone开发之常用代码:不断更新

    1,获取翻转事件,并开启翻转: 只要在viewcontroller的类中加入 -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOri ...

  5. 【转载】iphone开发之常用代码:不断更新

    转自:http://www.cnblogs.com/iphone520/archive/2012/01/09/2225160.html 1,获取翻转事件,并开启翻转: 只要在viewcontrolle ...

  6. iPhone开发的一些小技巧

    [转载]iPhone开发的一些小技巧 (2011-10-29 20:13:02) 转载原文 标签: 转载 原文地址:iPhone开发的一些小技巧作者:哈哈 一,修改状态栏: 1.加入[[UIAppli ...

  7. Windows下安装苹果iPhone开发环境xcode图文教程

    因为只有在mac系统上才能安装xcode哦~所以我们只有在Windows下先安装虚拟机,然后在虚拟机上安装mac系统. Xcode for Mac(苹果软件开发工具)  官方最新版 http://ww ...

  8. iPhone开发【一】从HelloWorld開始

    转载请注明出处,原文网址:http://blog.csdn.net/m_changgong/article/details/8013553 作者:张燕广 从经典的HelloWorld開始踏入iPhon ...

  9. 【转】在Windows中搭建iPhone开发环境

    很多朋友希望在体验或学习iphone开发,但是iphone开发环境一般需要 安装在mac计算机下mac os中. 这给许多朋友带来了额外成本投入. 网上已经有各种破解方法,在非苹果电脑上安装iphon ...

最新文章

  1. Web API与JWT认证
  2. 【log】12/11 checking project:(Laravel)snsTest
  3. python与人工智能编程-python学习(一)——python与人工智能
  4. 在游戏中强制关机,不能对关机提示框进行操作
  5. avalon 框架
  6. 在 Objective-C 中对 Block 应用 property 时的注意事项
  7. 穿墙透视真的来了!MIT华人团队超强动作检测模型,小黑屋照样夜视
  8. 计算营业额python_ARIMA时间序列分析-----Python实例(一周销售营业额预测)
  9. linux 隐藏显示终端光标
  10. mouseclick
  11. 什么是WAP?wap技术简介(转)
  12. 高等数学教材上册复习
  13. 2010-2011年美国大学综合排名
  14. luogu P2184 贪婪大陆
  15. 论文阅读——Aspect Sentiment Quad Prediction as Paraphrase Generation
  16. vue3中使用swiper7及autoplay无效问题
  17. linux的dve界面如何debug,VCS课时3:使用DVE进行Debug
  18. VIO--后端优化实践(坑)
  19. 队测 逆序对 permut
  20. 成功解决问题h5py\h5r.pyx, line 145, in init h5py.h5r AttributeError: type object 'h5py.h5r.Reference' ha

热门文章

  1. 微博 Android 启动广告,使用Xposed去除微博国际版的启动广告
  2. 十、非规则组织分析及其数学模型——锯齿形斜纹组织
  3. Visual Studio进行linux远程开发
  4. 随机邮箱_msgsafe - 一个处于半死不活状态的加密邮箱
  5. 从《四驱兄弟》到“联想中国”
  6. Django学习笔记《一》图书管理系统项目挂载到阿里云
  7. 软件工程学习笔记《四》需求分析
  8. 计算机网络【1】物理层
  9. Socket网络编程--小小网盘程序(2)
  10. gdb调试多进程程序