我有一个ViewController,它有20个点填充周围的主要内容的边缘。这是透明的颜色。
然后,我使用以下代码将其作为Modal打开。
noteDetailController.modalPresentationStyle = .overCurrentContext present(noteDetailController, animated: false, completion: nil)
我的想法是,我将设置一个UITapGestureRecognizer,允许用户点击填充区域中的任何位置来取消Modal。
在Modal ViewController中,此UITapGestureRecognizer将命中以下代码
self.parentController?.dismiss(animated: false, completion: nil)
我遇到了一些问题,Modal下的ViewController似乎可以响应按下屏幕的操作,并且在加载和关闭Modals时出现了很大的延迟。
这个逻辑看起来是正确的吗,我做事情的方式和你期望的一样吗?看起来好像present和dismiss开始不同步了,加载了几个Modals。
耽误您时间,实在对不起。
发布于 2018-03-07 00:32:07
当另一个视图控制器放在它上面时,你下面的视图控制器不应该获得触摸事件。
将模态控制器分割为Kind: Presentation,Presentation: Over Current Context,并将segue调用为performSegue(withIdentifier: "showModal", sender: nil)
@IBOutlet弱var containerView: UIView!覆盖函数viewDidLoad() { super.viewDidLoad() let tap = UITapGestureRecognizer(target: self,action:#selector(hide(gr:) tap.delegate = self view.addGestureRecognizer(tap) } func (_ 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(v.isDescendant: true) }
https://stackoverflow.com/questions/49134327
复制相似问题