iOS:使用 UIModalPresentationStyle.OverCurrentContext 时检测 dismissViewControllerAnimated

iOS: Detect dismissViewControllerAnimated while using UIModalPresentationStyle.OverCurrentContext

在我的 ViewControllerA 中,我尝试通过调用显示 ViewControllerB

let VC2 = ViewControllerB()
VC2.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext
presentViewController(VC2, animated: true, completion: nil)

因此 ViewControllerB 的内容显示在 ViewControllerA 的顶部。

当按下 ViewControllerB 中的按钮时,调用的是:

dismissViewControllerAnimated(true, completion: nil)

然而,ViewControllerAviewWillAppear没有被调用。

如果删除行 VC2.modalPresentationStyle = UIModalPresentationStyle.OverCurrentContext,则调用 ViewControllerAviewWillAppear

在使用 UIModalPresentationStyle.OverCurrentContext 时,不会调用 ViewControllerAviewWillAppear。在这种情况下,如何检测 ViewControllerB 是否在 ViewControllerA 中被关闭?我想 运行 ViewControllerA 中的一些代码,但不使用 ViewControllerB 中的 dismissViewControllerAnimatedcompletion

为什么不在 ViewControllerB 上创建自己的完成块?您可以在 ViewControllerA 上创建 ViewControllerB 的实例时分配它,然后您可以在 ViewControllerB 上调用 dismissViewControllerAnimated 时调用它。