Skip to content

Instantly share code, notes, and snippets.

@DonMag
Last active August 23, 2016 20:03
Show Gist options
  • Select an option

  • Save DonMag/ca3dce81fa05efb738fe8b7ec6198e81 to your computer and use it in GitHub Desktop.

Select an option

Save DonMag/ca3dce81fa05efb738fe8b7ec6198e81 to your computer and use it in GitHub Desktop.
// Need: adjustable time-between and distance-between Successive Taps
//
// as far as I can tell, UITapGestureRecognizer only recognizes a Successive Tap if it occurs
// within 0.35 seconds AND within 45 points
//
// Typical Single-Tap and Double-Tap Gesture Recognizer setup...
UITapGestureRecognizer *tapSingle = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gotSingleTap:)];
UITapGestureRecognizer *tapDouble = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gotDoubleTap:)];
tapSingle.numberOfTapsRequired = 1;
tapSingle.numberOfTouchesRequired = 1;
tapDouble.numberOfTapsRequired = 2;
tapDouble.numberOfTouchesRequired = 1;
[tapSingle requireGestureRecognizerToFail:tapDouble];
[_tapableView addGestureRecognizer:tapSingle];
[_tapableView addGestureRecognizer:tapDouble];
// I'd like to be able to add (for example)...
tapDouble.maxTimeBetweenTaps = 0.75; // Successive Tap within 3/4 of a second should count
tapDouble.maxDistanceBetweenTaps = 100; // Successive Tap within 100 pt radius should count
// the alternative is to use only Single-Tap Gesture Recognizer (or even plain-old UIGestureRecognizer)
// and then track time and distance with Timers / Variables / calculations / etc...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment