进入前台后,我正在执行一个请求,在此期间我将主窗口的根视图控制器更改为类似视图控制器的假启动屏幕,暂时保留当前根目录(这是带有嵌套导航的标签栏控制器控制器),执行请求后,根据响应,我将根交换回临时保存的“旧”根视图控制器(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
}
}
答案 0 :(得分:0)
我确实认为这样更容易,而不是这样更改 rootViewController :
我很确定您对这些选项之一没有问题。以“艰难的方式”更改根控制器对我来说似乎很危险。