窗口根更改后的 TabBar 可见性问题

问题描述

进入前台后,我正在执行一个请求,在此期间我将主窗口的根视图控制器更改为类似视图控制器的假启动屏幕,暂时保留当前根目录(这是带有嵌套导航的标签栏控制器控制器),执行请求后,根据响应,我将根交换回临时保存的“旧”根视图控制器(tabor 控制器)

与旧根交换后,tabor 显示在内页中,其中 hidesBottomBarWhenPushed 设置为 true,tabor 在任何 push 或 pop 转换后正确消失

我已经将这一点重构为更简单和更智能的,但我的问题仍然存在,会发生什么?以及为什么在根交换后设置了 hidesBottomBarWhenPushed 的 VC 上会显示标签栏

这是其中的一些代码:

private func animateRootChange(to viewController: UIViewController,_ completion: ((_ completed: Bool) -> Void)? = nil) {
    guard let window = window else { return }
    
    window.rootViewController = viewController
    
    UIView.transition(with: window,duration: 0.3,options: .transitionCrossDissolve,animations: nil) { (completed) in
        completion?(completed)
    }
}


func sceneWillEnterForeground(_ scene: UIScene) {
    guard let window = window,let currentRoot = window.rootViewController else {
        return
    }
            
    animateRootChange(to: LaunchScreenViewController(),nil)
    
    TheRequestWithFunctionCall { [weak self] (model: ForceUpdate) in
        guard let self = self else { return }
        
        aBoolean ? self.animateRootChange(to: currentRoot,nil) : self.animateRootChange(to: LogInViewController(),nil)

    } failure: { [weak self] (_) in
        
    }
}

解决方法

我确实认为这样更容易,而不是这样更改 rootViewController :

  • 如果它是一个简单的“假启动屏幕”,只需在当前顶视图控制器上显示一个视图控制器。
  • 使用带有隐藏标签的标签控制器,并在这两个标签之间切换。这是在两个状态(例如“已登录”和“未登录”)之间切换应用的好方法。

我很确定您对这些选项之一没有问题。以“艰难的方式”更改根控制器对我来说似乎很危险。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...