UITabBarController 隐藏 Bootom Tab Bar
2013-03-09 21:06
344 查看
需求:假设有三个页面 a, b, c, 三个页面可以随意切换,例如 a->b、b->c、c->a、b->a 、c->b 等,并且,我们希望三个页面只初始化一次。
思考:
通常,app会由几个ViewController组成,当由多个ViewController的时候,就需要对其进行管理,负责一个或者多个 ViewController管理并对其生命周期、屏幕旋转进行管理的类称为容器(Container View Controller),通常他们也是一个ViewController,例如UINavigationController、UITabbarController,也有极少数不是ViewController,例如UIPopoverController。
IOS5之后,已经支持自定义的Container View Controller,但对于简单的应用,比如只有三个页面,要去自定义一个 Container View Controller,好像没有什么必要, 于是我们考虑使用默认的一些Container View Controller。
UITabbarController应该最接近我们的需求。我们需要做的,就是将底部导航栏隐藏,并且自定义切换视图即可。
关键代码如下(在TabbarController的子页ViewController中实现)
在m文件中实现两个函数:
例子: http://download.csdn.net/detail/baijinwen/5125178
思考:
通常,app会由几个ViewController组成,当由多个ViewController的时候,就需要对其进行管理,负责一个或者多个 ViewController管理并对其生命周期、屏幕旋转进行管理的类称为容器(Container View Controller),通常他们也是一个ViewController,例如UINavigationController、UITabbarController,也有极少数不是ViewController,例如UIPopoverController。
IOS5之后,已经支持自定义的Container View Controller,但对于简单的应用,比如只有三个页面,要去自定义一个 Container View Controller,好像没有什么必要, 于是我们考虑使用默认的一些Container View Controller。
UITabbarController应该最接近我们的需求。我们需要做的,就是将底部导航栏隐藏,并且自定义切换视图即可。
关键代码如下(在TabbarController的子页ViewController中实现)
在m文件中实现两个函数:
/** * @brief 隐藏底部导航栏 */ - (void) HideTabBar:(UITabBarController *) tabbarcontroller { CGRect screenRect = [[UIScreen mainScreen] bounds]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.01]; float fHeight = screenRect.size.height; if( UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) { fHeight = screenRect.size.width; } for(UIView *view in tabbarcontroller.view.subviews) { if([view isKindOfClass:[UITabBar class]]) { [view setFrame:CGRectMake(view.frame.origin.x, fHeight, view.frame.size.width, view.frame.size.height)]; } else { [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)]; view.backgroundColor = [UIColor blackColor]; } } [UIView commitAnimations]; } /** * @brief 显示底部导航栏 */ - (void) ShowTabBar:(UITabBarController *) tabbarcontroller { CGRect screenRect = [[UIScreen mainScreen] bounds]; float fHeight = screenRect.size.height - 49.0; if( UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) ) { fHeight = screenRect.size.width - 49.0; } [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.01]; for(UIView *view in tabbarcontroller.view.subviews) { if([view isKindOfClass:[UITabBar class]]) { [view setFrame:CGRectMake(view.frame.origin.x, fHeight, view.frame.size.width, view.frame.size.height)]; } else { [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)]; } } [UIView commitAnimations]; }
例子: http://download.csdn.net/detail/baijinwen/5125178
相关文章推荐
- 如何隐藏Tab Bar Controller的Tab Bar
- UITabBarController:tab bar 的 image 太大、不清晰的解决方法
- 使用Tab Bar Controller 切换视图
- UINavigationController点击事件控制隐藏与显示(UITabBarController也同样适用)
- ((ios开发学习笔记五))手动创建Tab Bar Controller 程序
- 多个ViewController 只隐藏一个ViewController的UINavigationBar 和UITabBar
- Tab Bar Controller和Navigation Controller混合使用详细教程
- Storyboard Tutorial: Create Tab Bar Controller and Web View
- UITabBarController自定义以及隐藏
- Tab Bar Controller和Navigation Controller混合使用详细教程
- UITabbarController使用(二)隐藏和显示tabbar
- segue跳转到viewcontroller后tab bar item消失的问题
- UITabBarController 详解之 hidesBottomBarWhenPushed的正确用法
- How To Customise the Tab Bar (UITabBar) in an iPhone Application (Part 1 of 2)
- Tab Bar Controller(选项卡)的使用
- iOS学习- 05 Tab Bar Controller
- UITabBarController实现Tab切换
- iOS之UITabBarController与UINavigationController的动画隐藏
- UITabBarController,UITextView,UIToolbar,UISearchBar的综合应用
- ios——Tab Bar 的bottom Bar 隐藏与显示