user1120008
user1120008

Reputation: 1015

iOS press and hold gesture + tap

I have a press and hold gesture. During the the press and hold, I'd like to detect single taps elsewhere on the screen. The problem is that when I start tapping elsewhere on the screen the press and hold gesture is interrupted and does not call the "touch up" function. Is there a way to retain the press and hold while tapping elsewhere?

Upvotes: 3

Views: 5143

Answers (1)

Rok Jarc
Rok Jarc

Reputation: 18865

UIKit provides several mechanisms to make multiple UIGestureRecognizers on the same UIView work side by side. Which ones and how exactly depends on your needs and configuration.

One is - (void)requireGestureRecognizerToFail:(UIGestureRecognizer *)otherGestureRecognizer

However for your case you'll have to adopt UIGestureRecognizerDelegate protocol in your view.

Then you should implement gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: method.

For example:

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

Don't forget to make your UIView a delegate of it's getureRecognizers.

Some references:

UIGestureRecognizer Class Reference

UIGestureRecognizerDelegate Protocol Reference

Event Handling Guide for iOS

Upvotes: 3

Related Questions