【问题标题】:TabBar visibility issue after window root change窗口根更改后的 TabBar 可见性问题
【发布时间】:2021-07-27 20:11:34
【问题描述】:

进入前台后,我正在执行一个请求,在此期间我将主窗口的根视图控制器更改为像视图控制器一样的假启动屏幕,暂时保留当前根(这是带有嵌套导航的标签栏控制器控制器),在执行请求后,根据响应,我将根与临时保存的“旧”根视图控制器(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
        
    }
}

【问题讨论】:

    标签: swift uitabbarcontroller uitabbar uiwindow


    【解决方案1】:

    我确实认为与其这样更改 rootViewController 更容易:

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

    我很确定您对这些选项之一不会有任何问题。 “艰难地”更改根控制器对我来说似乎很危险。

    【讨论】:

    • 是的,我已经重构了这段代码,并在发布问题之前就显示了“启动屏幕”,但我的问题仍然存在,为什么会发生这种情况
    • 好的,很抱歉造成误会。那我不知道..肯定是由于内部管理视图/视图控制器层次结构(最近的选项卡/导航祖先)的方式。您是否尝试在进行转换之前调用“rootViewController.willMove(toParent: nil)”并在之后调用“didMove”?无论如何,我都会为那些想知道替代方案的人提供答案。
    猜你喜欢
    • 2011-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多