我正在创建一个应用程序,其中我将视图控制器放置在另一个应用程序上
介绍:当前上下文
但是当我尝试通过将顶部向底部拖动来关闭屏幕时,视图不会消失。
我还尝试添加一个按钮以使其关闭,但这也不起作用。
@IBAction func dis(_ sender: Any) {
navigationController?.popViewController(animated: true)
self.dismiss(animated: true)
}
那么,当使用“当前上下文”作为表示样式时,将顶部视图向下拖动时,如何关闭两个视图?
我正在使用“当前上下文”,因为以前的屏幕永远都不会再显示。并且我不想拖拽这两个,而是想拖拽一个使它们都消失。但是它似乎没有按预期工作。
答案 0 :(得分:1)
尽管“当前上下文”并非如@matt所述,
在这种情况下,您应该解雇提供此控制器的控制器,以同时解散这两个控制器:
self.presentingViewController!.dismiss(animated: true) // `!` is to makeing sure it's not crashing.
使用以下简单代码进行演示:
class ViewController: UIViewController {
@IBAction func present() {
let destination = storyboard!.instantiateInitialViewController()!
if presentingViewController != nil {
// You are not in the A
if presentingViewController?.presentingViewController != nil {
// You are in the C
presentingViewController?.presentingViewController?.dismiss(animated: true)
return
} else {
// You are in the B
destination.modalPresentationStyle = .currentContext
}
}
present(destination, animated: true, completion: nil)
}
}
ViewController
类@IBAction
答案 1 :(得分:0)