3

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.

entropid
  • 6,130
  • 5
  • 32
  • 45
  • I'm not sure you can add a gesture recognizer to a scrollview as it's native gesture handling probably takes precedence. the method gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: from the gesturerecognizer delegate might be interesting to try to implement and see if its called – manecosta Dec 31 '14 at 02:58
  • You can absolutely add gesture recognizers to a scrollview, but I think your scrollview's pan gesture's swallowing up your tap in this case. You have to require the scrollview's pan gesture to fail when the tap gesture's recognized. – Lyndsey Scott Dec 31 '14 at 03:12
  • http://stackoverflow.com/questions/16882737/scrollview-gesture-recognizer-eating-all-touch-events – Rakesh Dec 31 '14 at 03:20
  • Yeah definitely go with the solution @Rakesh linked to if you want to allow for both gestures to happen at once. Otherwise, you may want to require the scroll to fail during a tap. – Lyndsey Scott Dec 31 '14 at 03:22
  • It does not work. Setting that option to NO as explained in the linked question does not make the gesture work. Could it be because the Scroll View is almost fully filled by a UIWebView, so the UIWebView swallows up the gesture as well? – entropid Dec 31 '14 at 03:46

2 Answers2

5

The delegate class (conforming to UIGestureRecognizerDelegate) must implement

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

This way, the tap gesture will work.

entropid
  • 6,130
  • 5
  • 32
  • 45
1

The scroll view has it's own gesture recognizer.

You'll need to override that gesture recognizer or disable that first.

Then and then only, your gesture recognizer will work.

The better way to do this is to use the tap gesture inside the scroll view rather than adding your gesture recognizer.

Henit Nathwani
  • 442
  • 3
  • 10