我有一个ViewController
,在主要内容的边缘有20个点填充。这是透明的颜色。
然后我使用以下内容将其打开为Modal
。
noteDetailController.modalPresentationStyle = .overCurrentContext
present(noteDetailController, animated: false, completion: nil)
我的想法是,我会设置一个UITapGestureRecognizer
,允许用户点击填充区域的任何地方,以解雇Modal
。
以下是UITapGestureRecognizer
内部的Modal ViewController
self.parentController?.dismiss(animated: false, completion: nil)
我遇到的问题是ViewController
下面的Modal
似乎正在响应按下屏幕,并且在装载和解雇Modals
方面存在重大延迟。
这种逻辑看起来是否正确,我是否按照您期望的方式做事?这几乎看起来像present
和dismiss
开始发生不同步和几个Modals
加载。
谢谢你的时间。
下面的视图控制器不应该是触摸事件,而另一个视图控制器放在它上面。
performSegue(withIdentifier: "showModal", sender: nil)
@IBOutlet weak var containerView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
let tap = UITapGestureRecognizer(target: self, action: #selector(hide(gr:)))
tap.delegate = self
view.addGestureRecognizer(tap)
}
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
if let v = touch.view, v.isDescendant(of: containerView) {
return false
}
return true
}
@objc func hide(gr: UITapGestureRecognizer) {
dismiss(animated: true)
}