当你某一天发现app从首页控制器跳到下n级控制器时,需要隐藏底部tabar时,隐藏不了。
找了半天资料,发现控制器有一个叫hidesBottomBarWhenPushed的属性,但还不知道怎么
用,首先给控制器UIViewController加一个分类方法:
- (void)pushViewController:(nonnull UIViewController *)viewController {
viewController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:viewController animated:YES];
}
当要跳转的时候调用这个方法没有啥效果,后面我改成下面这样:
- (void)pushViewController:(nonnull UIViewController *)viewController {
self.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:viewController animated:YES];
self.hidesBottomBarWhenPushed = NO;
viewController.hidesBottomBarWhenPushed = YES;
}
完美解决,之后换了种写法:自定义一个XQUINavigationController继承自UiNavigaitonController,在里面重写下面这个方法:
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animatetd
{
if(self.childViewControllers.count > 0)//非根控制器
{
viewController.hidesBottomBarWhenPushed = YES;
}
[super pushViewController:viewController animated:animated];
}
然后tabBarController的根控制器使用XQUINavigationController同样完美解决。