如何立即替换呈现的 UIViewController?

How I can instantly replace presented UIViewController?

我已经实现了两个不同的 UIViewControllers,它们应该根据服务器响应和用户操作相互替换。为简单起见,假设我们有两个 UIViewControllersbutton 替换为另一个 ,这应该会触发此替换。

现在我需要替换那个部分,但问题是在关闭一个 屏幕 和显示另一个之间存在一些延迟。我想以某种方式摆脱它。我用 present method.

模态显示 UIViewController

我考虑将这两个屏幕作为 xib 文件中的视图,一个 UIViewController 将加载这些 xibs,将它们添加为 subViews 并在需要时将一个 subView 替换为另一个,但也许有一种方法可以使用两个 UIViewControllers?

我用来呈现控制器的代码:

let vc = UIViewController1()
vc.modalPresentationStyle = .overFullScreen
self.present(vc, animated: false, completion: nil)

并解散:

self.dismiss(animated: false, completion: nil)

将当前方法的 "animate" 参数设置为 false

  • 现在
let vc = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "YourViewController") as! YourViewController
self.present(vc, animated: false, completion: nil)
  • 解雇
self.dismiss(animated: false, completion: nil)

首先你发送通知parentclass现在[=27] =] 另一个 'viewController' 然后 dismiss current class

  • 注意:两者都存在 class 方法设置动画 false

你可以添加一个容器视图,在那个视图中你可以简单地添加你想要的控制器作为子视图控制器 official doc reference.

another reference