iOS5 UITapRecognizer for UIScrollView interfering with buttons. How to fix?

后端 未结 3 440
我在风中等你
我在风中等你 2020-12-28 23:20

I have a bunch of UIButtons within a UIView within a UIScrollView. I\'m trying to add a tap recognizer to the scroll view. The tap rec

3条回答
  •  無奈伤痛
    2020-12-28 23:45

    You could also use the gestureRecognizer:shouldReceiveTouch: method of the UIGestureRecognizerDelegate, which is documented here, to accomplish the same thing. It offers a little more flexibility, for instance, if you want to cancel certain touches, but not others. Here's an example,

    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
    {
        if ([touch.view.superview isKindOfClass:[UIButton class]]) return NO;
    
        return YES;
    }
    

提交回复
热议问题