tabBar隐藏动画,hidesBottombarWhenPushed
2016-03-23 11:19
579 查看
在UITabbarController包含的UINavigationController应用中,如果UINavigationController某一页(某个level)需要隐藏Tabbar,之前的做法是在push那一页之前,将那一页的ViewController中的hidesBottombarWhenPushed参数设为YES,这样当那一页push进UINavigationController中时,底部的Tabbar就会隐藏掉。
但是这种方法有一个潜在的而又巨大的问题,假设现在我有3个ViewController A,B,C,其中为Navigation的RootViewController,A中push B,B中push C。这时,如果我想要在B中隐藏Tabbar,而在C中显示Tabbar,根据最朴素的想法就是:
然而很可惜,虽然A中push B能让Tabbar隐藏,但是B中push C,就没办法让Tabbar显示出来了。这是一个比较郁闷的问题,我只能猜想其中的原理是,当设置某一层hidesBottomBarWhenPushed = YES之后,UITabbarController就像不存在一样,就连调用self.tabbarController或者self.navigationController.tabbarController也应该是nil。
所以解决办法只能是手动隐藏Tabbar。
//代码中用到的宏:
#define HEIGHTIPHONE [UIScreen mainScreen].bounds.size.height
我的个人观点:
首先对作者表示感谢,很给力,给我门找到了一个平滑的方法,看着很流畅
1 、 在做显示动画的时候我建议写在viewDidAppear里面,这样看着舒服。
2、 两个方法分开,需要隐藏的视图光写隐藏就好了,
3 、 有的时候不需要显示动画,比如再分栏来回切换的时候,tabBar不需要做显示动画,只有从二级界面返回的时候需要,这样我们可以设置一个属性
@property (nonatomic ,assign)BOOL isPush;// 是否推出了二级界面
当push的时候设置成yes,pop回来做完动画,就设置成no。
原文地址:点击打开链接
但是这种方法有一个潜在的而又巨大的问题,假设现在我有3个ViewController A,B,C,其中为Navigation的RootViewController,A中push B,B中push C。这时,如果我想要在B中隐藏Tabbar,而在C中显示Tabbar,根据最朴素的想法就是:
//SecondLevel即为B,此代码在A中进行 SecondLevelViewController *_2vc = [[SecondLevelViewController alloc]initWithNibName:@"SecondLevelViewController" bundle:nil]; _2vc.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:_2vc animated:YES]; //ThirdLevel即为C,此代码在B中进行 ThirdLevelViewController *_3vc = [[ThirdLevelViewController alloc]initWithNibName:@"ThirdLevelViewController" bundle:nil]; _3vc.hidesBottomBarWhenPushed = NO; [self.navigationController pushViewController:_3vc animated:YES];
然而很可惜,虽然A中push B能让Tabbar隐藏,但是B中push C,就没办法让Tabbar显示出来了。这是一个比较郁闷的问题,我只能猜想其中的原理是,当设置某一层hidesBottomBarWhenPushed = YES之后,UITabbarController就像不存在一样,就连调用self.tabbarController或者self.navigationController.tabbarController也应该是nil。
所以解决办法只能是手动隐藏Tabbar。
- (void) hideTabBar:(UITabBarController *) tabbarcontroller { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; for(UIView *view in tabbarcontroller.view.subviews) { if([view isKindOfClass:[UITabBar class]]) { [view setFrame:CGRectMake(view.frame.origin.x, HEIGHTIPHONE, view.frame.size.width, view.frame.size.height)]; } else { [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, HEIGHTIPHONE)]; } } [UIView commitAnimations]; } - (void) showTabBar:(UITabBarController *) tabbarcontroller { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; for(UIView *view in tabbarcontroller.view.subviews) { if([view isKindOfClass:[UITabBar class]]) { [view setFrame:CGRectMake(view.frame.origin.x, HEIGHTIPHONE-view.frame.size.height, view.frame.size.width, view.frame.size.height)]; } else { [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, HEIGHTIPHONE-49)]; } } [UIView commitAnimations]; }
-(void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; if (_isPush) { [self showTabBar:self.tabBarController]; } _isPush = NO; }
- (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [self hideTabBar:self.tabBarController]; }
//代码中用到的宏:
#define HEIGHTIPHONE [UIScreen mainScreen].bounds.size.height
我的个人观点:
首先对作者表示感谢,很给力,给我门找到了一个平滑的方法,看着很流畅
1 、 在做显示动画的时候我建议写在viewDidAppear里面,这样看着舒服。
2、 两个方法分开,需要隐藏的视图光写隐藏就好了,
3 、 有的时候不需要显示动画,比如再分栏来回切换的时候,tabBar不需要做显示动画,只有从二级界面返回的时候需要,这样我们可以设置一个属性
@property (nonatomic ,assign)BOOL isPush;// 是否推出了二级界面
当push的时候设置成yes,pop回来做完动画,就设置成no。
原文地址:点击打开链接
相关文章推荐
- mysql中You can’t specify target table for update in FROM clause错误解决方法
- 每天学一点MATLAB函数——软件操作函数
- 五类关节属性Joint的用法
- 保持app大小不变 不随系统设置改变而改变
- Linux Shell编程基础
- Matlab中保存图像时,图形窗口大小的控制
- spin_lock、spin_lock_irq、spin_lock_irqsave区别【转】
- 无题
- C++中的数组和指针
- 第17条:实现description方法
- ssh用root直接登录失败的问题
- 案例分析:把指定的信息输出到指定的文件中
- VC++改变窗口背景颜色和使得Static控件背景透明
- ThinkPHP模板循环输出Volist标签用法实例详解
- 6.UITableView增强
- bzoj 1208[HNOI 2004] 宠物收养所
- 深入理解HTTP协议
- Struts2之validate数据校验两种方式
- Linux下百度云盘报 获取bdstoken失败
- Android显示系统框架原理介绍