首页 文章

如何解析viewController到rootViewController而不在解除进程之间显示任何VC?

提问于
浏览
0

假设我有以下风投:

RootVC - > VC A - > VC B.

我正在使用present方法将视图控制器从RootVC呈现给VC A然后再呈现给VC B.现在我在VC B上,我想要从VC B中解除回到RootVC

self.view.window!.rootViewController?.dismiss(animated: true, completion: nil)

它有效,但我仍然看到VC A在解雇过程中出现 . 然后,我尝试这种方法

self.presentationController?.presentedViewController.dismiss(animated: true, completion: nil)

它也可以解散回根VC,但我仍然看到VC A正在进行中 .

我的问题是有没有办法在解雇过程中不显示VC A?我已经尝试了动画:false但仍然得到相同的结果 . 谢谢!

2 回答

  • -1

    您需要将 modalPresentationStyle 中的更改更改为 .custom . 当前可见控制器的视图是透明的时, custom 将允许您查看 presentingViewController 视图 .

    现在,当您想要返回当前呈现堆栈的根视图时,需要调用方法 dismissToRootViewController(animated: completion:) .

    在此方法的实现中,将允许所有中间呈现视图控制器视图是透明的,这将使您从 VC cRootVC 关闭动画 .

    extension UIViewController {
        func dismissToRootViewController(animated: Bool, completion: (() -> Swift.Void)? = nil) {
            var viewController = self.presentingViewController
            while viewController?.presentingViewController != nil {
                viewController?.view.alpha = 0.0
                viewController = viewController?.presentingViewController
            }
            self.dismiss(animated: true) {
                viewController?.dismiss(animated: false, completion: completion)
            }
        }
    }
    
  • 0

    您可以尝试使用此:

    navigationController?.popToRootViewController(animated: false)
    

相关问题