[英]Issue with Modal present and dismiss
我有一個ViewController
,它在主要內容的邊緣周圍有20個空白點。 這是透明的顏色,是透明的。
然后,我使用以下代碼將其作為Modal
打開。
noteDetailController.modalPresentationStyle = .overCurrentContext present(noteDetailController, animated: false, completion: nil)
我的想法是,我將設置一個UITapGestureRecognizer
以允許用戶點擊填充區域中的任何位置以消除Modal
。
以下是此UITapGestureRecognizer
在Modal ViewController
self.parentController?.dismiss(animated: false, completion: nil)
我遇到的問題是, Modal
下的ViewController
似乎響應按下屏幕,並且在加載和關閉Modal
存在Modals
滯后。
這種邏輯看起來是否正確,我是否按照您期望的方式工作? 它幾乎好像present
並dismiss
開始發生不同步,幾個Modals
被加載。
謝謝你的時間。
當另一個視圖控制器放置在其上方時,其下方的視圖控制器不應發生觸摸事件。
performSegue(withIdentifier: "showModal", sender: nil)
使用IBOutlet將模態的容器視圖連接到模態視圖控制器,將UITapGestureRecognizer添加到模態的視圖(填充),並實現UIGestureRecognizerDelegate方法以檢測抽頭確實僅在填充而不是在容器視圖本身中:
@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) }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.