iOS14.0系统下popToRootViewControllerAnimated导致底部TabBar消失的解决方案

两种解决方案:

  1. 禁用popToRootViewControllerAnimated:的动画, 使用之处依次处理
    [self.navigationController popToRootViewControllerAnimated:YES];
//改为
[self.navigationController popToRootViewControllerAnimated:NO];

  1. 保留动画, 修改导航控制器的基类中pushViewController: animated:方法
/**
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if (self.viewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
    } else {
        viewController.hidesBottomBarWhenPushed = NO;
    }
    [super pushViewController:viewController animated:animated];
}
*/
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if (self.viewControllers.count > 0) {
        // 当前导航控制器只有一个viewController的时候push设置隐藏即可
        if (self.viewControllers.count == 1) {
            viewController.hidesBottomBarWhenPushed = YES;
        }
    } else {
        viewController.hidesBottomBarWhenPushed = NO; 
    }
    [super pushViewController:viewController animated:animated];
}

你可能感兴趣的:(iOS14.0系统下popToRootViewControllerAnimated导致底部TabBar消失的解决方案)