将 iOS 升级到 14 后,使用 popToRootViewControllerAnimated:YES 返回到首页,会导致 TabBar 被隐藏,初步猜测是 iOS 的 bug。
Xcode 版本: 12.1
iOS 版本: 14.1
解决方案
1、将 popToRootViewControllerAnimated: 参数设为 NO
[self.navigationController popToRootViewControllerAnimated:NO];
这种方案牺牲了动画效果,如果对此有要求的请看方案二
2、创建 UINavigationController 子类并重写 popToRootViewControllerAnimated: 方法
- (NSArray<__kindof UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated {
if (self.viewControllers.count > 1) {
self.topViewController.hidesBottomBarWhenPushed = NO;
}
NSArray<__kindof UIViewController *> *viewControllers = [super popToRootViewControllerAnimated:animated];
// self.viewControllers has two items here on iOS14
return viewControllers;
}