ma11hew28
ma11hew28

Reputation: 126507

How to handle single vs double touches on iPhone

I want to do something similar to iPhone's photo viewer. When you single tap, the UI bars disappear after a short delay. When you double tap, it zooms in. But I don't want anything to happen on double tap because I haven't yet implemented zooming in.

Anyone know how to do this?

[This post] didn't really help. Unless you tell me it's necessary to subclass UIGestureRecognizer. Then, I think I could figure it out. Anyone have any examples?

Upvotes: 0

Views: 259

Answers (3)

mahboudz
mahboudz

Reputation: 39376

Here's some code that should help:

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
[scrollView addGestureRecognizer:singleTap];
[singleTap release];

UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
[doubleTap setNumberOfTapsRequired: 2];
[scrollView addGestureRecognizer:doubleTap];
// this next line will hold callbacks to singleTap until enough time has gone by that doubleTap is not a possibility.  If a doubleTap happens, singleTap will not get called. Otherwise, singleTap's callback gets called.
[singleTap requireGestureRecognizerToFail:doubleTap];
[doubleTap release];

Upvotes: 0

ma11hew28
ma11hew28

Reputation: 126507

Check out Three20's PhotoView. It does what you're looking to do.

Upvotes: 0

jer
jer

Reputation: 20236

Look at the UITapGestureRecognizer documentation. There's two properties you want to look at:

  • numberOfTapsRequired; and
  • numberOfTouchesRequired

Upvotes: 2

Related Questions