有些情况是这样的,比如首页是显示tabbar的,但是push之后需要将tabbar隐藏掉,返回时再显示tabbar。
方式一:hidesBottomBarWhenPushed,在push的时候设置这个熟悉,达到我们想要的目的,缺点是每次在push的时候都需要设置,很麻烦!
UiViewController *viewCtrl = [[UiViewController alloc]init];
viewCtrl.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:ctrl animated:YES];
// 这样back回来的时候,tabBar会恢复正常显示
self.hidesBottomBarWhenPushed = NO;
方式二:自定义一个导航控制器,继承UINavigationController
写到这里也许你想到了,就是重写方法- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated,
然后进行处理
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
// 首页不需要隐藏tabbar
NSString *ctrlName = NSStringFromClass([viewController class]);
if ([ctrlName isEqualToString:@"HomeViewController"] ) {
viewController.hidesBottomBarWhenPushed = NO;
}else{
// 其他push时需要隐藏tabbar
viewController.hidesBottomBarWhenPushed = YES;
}
// 这一句别忘记了啊
[super pushViewController:viewController animated:animated];
}