簡體   English   中英

存在莫代爾和解散的問題

[英]Issue with Modal present and dismiss

我有一個ViewController ,它在主要內容的邊緣周圍有20個空白點。 這是透明的顏色,是透明的。

然后,我使用以下代碼將其作為Modal打開。

noteDetailController.modalPresentationStyle = .overCurrentContext present(noteDetailController, animated: false, completion: nil)

我的想法是,我將設置一個UITapGestureRecognizer以允許用戶點擊填充區域中的任何位置以消除Modal

以下是此UITapGestureRecognizerModal ViewController

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

我遇到的問題是, Modal下的ViewController似乎響應按下屏幕,並且在加載和關閉Modal存在Modals滯后。

這種邏輯看起來是否正確,我是否按照您期望的方式工作? 它幾乎好像presentdismiss開始發生不同步,幾個Modals被加載。

謝謝你的時間。

當另一個視圖控制器放置在其上方時,其下方的視圖控制器不應發生觸摸事件。

  1. 使用“種類:當前模態,顯示:當前上下文”對模態控制器進行segue,並將該segue稱為performSegue(withIdentifier: "showModal", sender: nil)
  2. 確保模態視圖控制器的視圖已選中“已啟用用戶交互”並具有清晰的彩色背景。
  3. 使用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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM