自定义tabbar中怎么在push之后ios push隐藏tabbar

&&& 今天工作中用到了自定义tabBar,因此就隐藏掉了系统的tabBar,然后用view自定义了一个tabBar,效果还挺好。但是接下来问题来了,当我任意tabbar所在的contoller里面push到子页面的时候就出现了tabBar无法隐藏的问题,和系统的隐藏不太一样,搞了半天终于弄好了,拿出来与大家一块分享。
1、在自定义的TabBarController.m里写方法
-(void)setHidesBottomBarWhenPushed:(BOOL)hidesBottomBarWhenPushed{
&&&&self.你自己定义的View.hidden = hidesBottomBarWhenP
2、在你要隐藏的子页面中
-(void)viewWillAppear:(BOOL)animated
&&&&self.tabBarController.hidesBottomBarWhenPushed = YES;
3、pop到上一页(在你要隐藏的子页面中)
- (void)viewWillDisappear:(BOOL)animated {
&&& self.tabBarController.hidesBottomBarWhenPushed = NO;
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:22474次
排名:千里之外
原创:20篇
(1)(1)(1)(1)(1)(9)(4)(2)iOS+TabBar的隐藏,hidesBottomBarWhenPushed的正确使用 - 简书
iOS+TabBar的隐藏,hidesBottomBarWhenPushed的正确使用
项目中在跳转子页面的时候隐藏tabbar是个很常见的需求,苹果也提供了方便的方法,即设置控制器的hidesBottomBarWhenPushed属性,但设置错误,就会出现莫名其妙的问题,曾经就掉入过坑中直到抓狂?
二、hidesBottomBarWhenPushed作用
A view controller added as a child of a navigation controller can display an optional toolbar at the bottom of the screen. The value of this property on the topmost view controller determines whether the toolbar is visible. If the value of this property is YES, the toolbar is hidden. If the value of this property is NO, the bar is visible.
???上面是苹果对属性hidesBottomBarWhenPushed的解释:???
大意是:已经添加到导航控制器的子控制器可选择性的展示屏幕底部的toolbar。 最顶部的子控制器的属性值(hidesBottomBarWhenPushed)决定toolbar是否可见,如果属性值为YES,toolbar隐藏,为NO,则可见。
三、例子:A -&B,A push 显示B,push时B底部的tabor隐藏
1. 曾经错误的设置(以下的设置都是在A控制器中)
设置:在pushB之前,使 A.hidesBottomBarWhenPushed = Yes;
// A push B
- (IBAction)nextPage:(id)sender
// push之前设置A的hidesBottomBarWhenPushed属性
BViewController *BVC = [[BViewController alloc] init];
self.hidesBottomBarWhenPushed = YES;
//self为A控制器
[self.navigationController pushViewController:BVC animated:YES];
在点击next的时候,确实成功跳转并隐藏了tabbar,满意?;
可返回的以后,tabbar隐藏了,这不是我想要的结果?;
那解决问题呗,在viewWillAppear的时候设置?
// 解决返回时tabbar的隐藏问题
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.tabBarController.tabBar.hidden = NO;
self.hidesBottomBarWhenPushed = NO;
设置后算是比较符合需求了,虽然效果怪怪的。本以为算是成功了,可再次push时又出问题了??????
2. 正确做法
查查查资料。。。算是理解了,再看看苹果解释,有两个关键点:1.已经添加到导航控制器的子控制器;2.最顶部的控制器;
系统在push B的时候,B控制器其实已经加入到导航控制器的子控制器中了;
此时,B才是最顶部的控制器,B的hidesBottomBarWhenPushed属性才是正确控制tabbar隐藏的关键,而不是A的;
既然找到原因,那就改:
清除先前的相关设置
// 去除先前的设置,例如下面的
A.hidesBottomBarWhenPushed = Yes;
A.tabBarController.tabBar.hidden = NO;
A.hidesBottomBarWhenPushed = NO;
正确设置:
/// A push B
- (IBAction)nextPage:(id)sender {
// 设置B的hidesBottomBarWhenPushe
BViewController *BVC = [[BViewController alloc] init];
BVC.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:BVC animated:YES];
结果: 运行,多次测试,无误,放心了。?
上面的设置只需要在NavigationController的根控制器push到其他页面的时候设置一下就好,其他子页面都会隐藏tabbar,不用再在其他页面设置。
其实还可以整体设置下,重写UINavigationController中的push方法,免得每个tab下的控制器都设置。
// 重写自定义的UINavigationController中的push方法
// 处理tabbar的显示隐藏
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
if (self.childViewControllers.count==1) {
viewController.hidesBottomBarWhenPushed = YES; //viewController是将要被push的控制器
[super pushViewController:viewController animated:animated];&&&&self.hidesBottomBarWhenPushed=YES;
&&&&NextViewController
*next=[[NextViewController alloc]init];
&&&&[self.navigationController
pushViewController:next animated:YES];
&&&&self.hidesBottomBarWhenPushed=NO;
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:2476次
排名:千里之外
原创:18篇
评论:12条
(2)(2)(1)(1)(5)(7)隐藏tabbar的属性hidesBottomBarWhenPushed
来源:博客园
项目中有需求是A视图控制器push之后B视图控制器需要隐藏底部的tabbar,在pop之后A视图控制器仍然显示tabbar. 其实不需要在push操作时敲 self . hidesBottomBarWhenPushed = NO ;,然后再pop返回时再设置成NO. 对于这个全局属性,可以在A中 - ( void )viewWillAppear:( BOOL )animated { self . hidesBottomBarWhenPushed = YES ; } - ( void )viewDidDisappear:( BOOL )animated { self . hidesBottomBarWhenPushed = NO ; } 这样就实现了。
免责声明:本站部分内容、图片、文字、视频等来自于互联网,仅供大家学习与交流。相关内容如涉嫌侵犯您的知识产权或其他合法权益,请向本站发送有效通知,我们会及时处理。反馈邮箱&&&&。
学生服务号
在线咨询,奖学金返现,名师点评,等你来互动

我要回帖

更多关于 自定义push 的文章

 

随机推荐