UITapGestureRecognizer tap on self.view but ignore subviews

后端 未结 12 813
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-30 21:49

I need to implement a feature that will invoke some code when I double tap on the self.view (view of UIViewCotroller). But the problem that I have other UI obje

12条回答
  •  孤街浪徒
    2020-11-30 22:40

    And for the Swift variant:

    func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldReceiveTouch touch: UITouch) -> Bool {
        if touch.view.isDescendantOfView(yourSubView){
            return false
        }
        return true
    }
    

    Good to know, isDescendantOfView returns a Boolean value indicating whether the receiver is a subview of a given view or identical to that view.

提交回复
热议问题