背景: 最近在做一个项目中 需要在tabbar中的一个子控制器中隐藏tabbar。 我是tabbar我是自定义的XIB 视图addsubview到tabbar上。
首先po 一个在网上查到的解决方法:
UIWindow * window = [UIApplication sharedApplication].keyWindow;
CustomTabBar * ct =(CustomTabBar *) window.rootViewController;
ct.bgView.hidden = YES;
原文地址:http://blog.csdn.net/zx6268476/article/details/45692141
坑:我在跳出来的时候 tabbar 不显示 - -
我再说我的解决思路:tabbarViewcongtroller 都是通过 push和 pop 方法进行 自控制器的跳转的,所以我们自定义navigationcontroller,来拦截push和pop 方法。废话不多说,上代码
1. 首先自定义一个CustomNavigationController(名字自己起)继承与UINavigationController,CustomNavigationController.m中拦截系统的push方法,进行重写:
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
[super pushViewController:viewController animated:animated];
}
-(UIViewController *)popViewControllerAnimated:(BOOL)animated{
return [super popViewControllerAnimated:animated];
}
[super pushViewController:viewController animated:animated];
}
-(UIViewController *)popViewControllerAnimated:(BOOL)animated{
return [super popViewControllerAnimated:animated];
}
2. 在自定义的TabBarController.m里写如下方法:
-(void)setHidesBottomBarWhenPushed:(BOOL)hidesBottomBarWhenPushed{
你的自定义View.hidden = hidesBottomBarWhenPushed;
self.tabBar.hidden = hidesBottomBarWhenPushed;
}
你的自定义View.hidden = hidesBottomBarWhenPushed;
self.tabBar.hidden = hidesBottomBarWhenPushed;
}
3. 在你要隐藏tabbar的界面添加如下两个方法:
-(void)viewWillAppear:(BOOL)animated{
self.tabBarController.hidesBottomBarWhenPushed = YES;
}
-(void)viewWillDisappear:(BOOL)animated{
self.tabBarController.hidesBottomBarWhenPushed = NO;
}
self.tabBarController.hidesBottomBarWhenPushed = YES;
}
-(void)viewWillDisappear:(BOOL)animated{
self.tabBarController.hidesBottomBarWhenPushed = NO;
}