我不知道如何在 Swift中实现以下功能: 我在我的iPad应用程序中显示模态表单弹出窗口.为了驳回这个观点,我添加了一个解除它的按钮.但我真正想要的是当你点击视图外面时它会被忽略
我在我的iPad应用程序中显示模态表单弹出窗口.为了驳回这个观点,我添加了一个解除它的按钮.但我真正想要的是当你点击视图外面时它会被忽略.与popover几乎相同的行为.我尝试通过添加点击手势来实现这一点,使其成为一个弹出窗口,任何演示样式,没有任何作用.
有人可能这样做,以便你可以指出我正确的方向?
我必须在我的应用程序中显示一些像弹出窗口的屏幕,所以我已经创建了如下所示的基类:class MyBasePopUp: UIViewController, UIGestureRecognizerDelegate { var tap: UITapGestureRecognizer! override func viewDidAppear(_ animated: Bool) { tap = UITapGestureRecognizer(target: self, action: #selector(onTap(sender:))) tap.numberOfTapsRequired = 1 tap.numberOfTouchesRequired = 1 tap.cancelsTouchesInView = false tap.delegate = self self.view.window?.addGestureRecognizer(tap) } internal func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { return true } internal func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool { let location = touch.location(in: self.view) if self.view.point(inside: location, with: nil) { return false } else { return true } } @objc private func onTap(sender: UITapGestureRecognizer) { self.view.window?.removeGestureRecognizer(sender) self.dismiss(animated: true, completion: nil) }
这只是为了解除弹出窗口,如果您有多个手势,请小心.