iOS14发布后,项目中多处出现了这个问题,主要是在iOS14 popToRootViewControllerAnimated后tabbr就不见了,是由hidesBottomBarWhenPushed导致,下面是简单的触发场景:
A push B,B push C,C popToRootViewControllerAnimated:YES,这时候tabbar就不见了。
如果一级一级的pop就不会有这个问题,如果把popToRoot的Animated改为NO也不会有这个问题。
如何解决:
1、那里出现就解决那里,pop root之前先设置当前VC的hidesBottomBarWhenPushed
self.hidesBottomBarWhenPushed = NO;
[self.navigationController popToRootViewControllerAnimated:YES];
2、统一处理,重写UINavigationController的popToRootViewControllerAnimated方法
– (NSArray<__kindof UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated {
if (animated) {
UIViewController *topVC = self.viewControllers.lastObject;
topVC.hidesBottomBarWhenPushed = NO;
}
return [super popToRootViewControllerAnimated:animated];
}
3、从最初出发,按需设置,重写UINavigationController的pushViewController方法
– (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
if (self.viewControllers.count == 1) {
viewController.hidesBottomBarWhenPushed = YES;
} else {
viewController.hidesBottomBarWhenPushed = NO;
}
[super pushViewController:viewController animated:animated];
}
请根据各自项目选择合适的方案。😄