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
}

 

posted @ 2023-07-27 16:07  zk1947  阅读(210)  评论(0编辑  收藏  举报