Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITapGestureRecognizer on UIScrollView

I setup a UITapGestureRecognizer on a UIScrollView in the storyboard. The Scroll View contains other contents (two UIView, one UIWebView).

The Gesture Recognizer properties are as follows:

  • Action: dismissPopover
  • delegate: postViewController
  • gestureRecognizers: Scroll View
  • state: enabled
  • numberOfTapsRequired: 1
  • numberOfTouchesRequired: 1
  • cancelTouchesInView: YES
  • delayTouchesBegan: NO
  • delayTouchesEnded: YES

The Scroll View (relevant) properties are as follows:

  • userInteractionEnabled: YES
  • canCancelContentTouches: YES

However, when I tap anywhere on the Scroll View, the gesture does not work.

like image 219
entropid Avatar asked May 13 '26 17:05

entropid


1 Answers

The delegate class (conforming to UIGestureRecognizerDelegate) must implement

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}

This way, the tap gesture will work.

like image 187
entropid Avatar answered May 16 '26 08:05

entropid