iOS view 点击事件分发处理

当创建自定义view时,如果底层view与上层view(button)都需要处理点击事件时:
继承UIGestureRecognizerDelegate,设置底层view的UITapGestureRecognizer的delegate为self,实现shouldReceive的方法

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
    if (touch.view?.isKind(of: self.classForCoder))! {
            return true
    }else{
            return false
    }
}

你可能感兴趣的:(iOS view 点击事件分发处理)