iOS首頁控制器跳轉隱藏app底部的tabBar
當你某一天發現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同樣完美解決。
iOS首頁控制器跳轉隱藏app底部的tabBar