UIView上添加UITapGestureRecognizer手势后,导致view上的UIButton无响应
通过手势代理方法判断处理,代码如下
let tap = UITapGestureRecognizer(target: self, action: #selector(tapAction)) tap.delegate = self view.addGestureRecognizer(tap)
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool { guard let touchView = touch.view else { return false } if touchView.isKind(of: UIButton.self) { return false } return true }