entropid
entropid

Reputation: 6239

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:

The Scroll View (relevant) properties are as follows:

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

Upvotes: 3

Views: 3927

Answers (2)

Henit Nathwani
Henit Nathwani

Reputation: 442

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.

Upvotes: 1

entropid
entropid

Reputation: 6239

The delegate class (conforming to UIGestureRecognizerDelegate) must implement

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

This way, the tap gesture will work.

Upvotes: 5

Related Questions