需求:自定义一个提示框,添加一个全屏的透明遮罩层,点击遮罩层提示框隐藏消失,点击提示框不做响应。
问题:在遮罩层正常添加点击手势的话,子视图同样也会响应父视图的手势。我们需要隔绝父视图的手势。
解决:UIGestureRecognizer签订代理UIGestureRecognizerDelegate
实现代理方法:
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
}
在代理方法中处理视图是否响应手势。
let tap = UITapGestureRecognizer(target: self, action: #selector(clickTapAction))
tap.delegate = self
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
if (touch.view?.isDescendant(of: self.backView))! {
return false
}
return true
}