Re: UITapGestureRecognizer and state/action w/rt numberOfTapsRequired
Re: UITapGestureRecognizer and state/action w/rt numberOfTapsRequired
- Subject: Re: UITapGestureRecognizer and state/action w/rt numberOfTapsRequired
- From: Matt Neuburg <email@hidden>
- Date: Thu, 10 Nov 2011 08:07:02 -0800
On Tue, 08 Nov 2011 12:56:03 -0800, Ben Kennedy <email@hidden> said:
>>From http://developer.apple.com/library/ios/#documentation/uikit/reference/UITapGestureRecognizer_Class/Reference/Reference.html :
>
>> Although taps are discrete gestures, they are discrete for each state of the gesture recognizer; thus the associated action message is sent when the gesture begins and is sent for each intermediate state until (and including) the ending state of the gesture. Code that handles tap gestures should therefore test for the state of the gesture, for example:
>>
>> - (void)handleTap:(UITapGestureRecognizer *)sender { if (sender.state == UIGestureRecognizerStateEnded) { // handling code } }
>
>This suggests that if I set numberOfTapsRequired = 2, I should be able to get action for both a single tap (i.e. the first of a pair of taps), as well a double-tap. However, in iOS 5 this does not appear to be the case; my action method is not called until the numberOfTapsRequired has been satisfied.
>
>In order to respond to both a single and double tap, do I thus need to attach two gesture recognizers?
>
>Do I mis-understand the doc
Yes.
If you're going to use gesture recognizers, then if you want to recognize both a single and double tap, it was always the case that you needed to attach two gesture recognizers. And if you want it to recognize only one, then you must also require that the double tap fail before the single tap can succeed.
This will cause a time delay after the single tap, but there is NO OTHER WAY this can work. Even if you drop down to the level of manual touches, you will need to use a delay. Think about it: the only way to learn that a second tap will not follow the first is to WAIT AND SEE. (The telepathy API is not yet operative on every device.)
Apple has stated that they would prefer you to rethink your interface in a case like this. There are two ways to rethink it:
(1) Don't do that.
(2) Do that, but don't include the "fail" requirement; instead, do it in such a way that it's okay for the single tap to respond immediately. When the double tap then *also* succeeds, you can cancel whatever you did in response to the single tap. This solution is not always feasible, as Apple's own apps show (like Mobile Safari). But it eliminates the delay from the user's point of view.
This is all *very* well covered in my book, by the way.
m.
--
matt neuburg, phd = email@hidden, <http://www.apeth.net/matt/>
A fool + a tool + an autorelease pool = cool!
Programming iOS 4!
http://www.apeth.net/matt/default.html#iosbook_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden