Modal存在和解雇的问题

问题描述 投票:0回答:1

我有一个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方面存在重大延迟。

这种逻辑看起来是否正确,我是否按照您期望的方式做事?这几乎看起来像presentdismiss开始发生不同步和几个Modals加载。

谢谢你的时间。

ios swift
1个回答
0
投票

下面的视图控制器不应该是触摸事件,而另一个视图控制器放在它上面。

  1. 对模态控制器做一个segue作为Kind:呈现模态,演示:当前上下文,并调用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) }
© www.soinside.com 2019 - 2024. All rights reserved.