UITapGestureRecognizer tap on self.view but ignore subviews

后端 未结 12 789
佛祖请我去吃肉
佛祖请我去吃肉 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:39

    I had to prevent the gesture on the child view. The only thing that worked is to allow and keep the first view and prevent gesture in all the next views:

       var gestureView: UIView? = nil
    
        func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
            if (gestureView == nil || gestureView == touch.view){
                gestureView = touch.view
                return true
            }
            return false
         }
    

提交回复
热议问题