Re: UITapGestureRecognizer and state/action w/rt numberOfTapsRequired

2011-11-10 Thread Matt Neuburg
On Tue, 08 Nov 2011 12:56:03 -0800, Ben Kennedy  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 = m...@tidbits.com, 
A fool + a tool + an autorelease pool = cool!
Programming iOS 4!
http://www.apeth.net/matt/default.html#iosbook___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: UITapGestureRecognizer and state/action w/rt numberOfTapsRequired

2011-11-08 Thread Ben Kennedy
On 08 Nov 2011, at 2:17 pm, Conrad Shultz wrote:

> I'm not sure why you aren't receiving intermediate messages, but trying
> to key off intermediates is not a great pattern anyway.  Just attach two
> gesture recognizers, then you have the benefit of separating your action
> methods (which will be nice if you decide to change gestures later on).

Thanks Conrad (and Ludo, off-list); that's what I've decided to do.  Given what 
the doc said I thought I could be a bit lighter-weight by avoiding the need for 
a second gesture recognizer if I got the behaviour for free, but I agree with 
you that it's probably a better design to do it this way.

cheers,

-b

--
Ben Kennedy, chief magician
Zygoat Creative Technical Services
http://www.zygoat.ca

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: UITapGestureRecognizer and state/action w/rt numberOfTapsRequired

2011-11-08 Thread Conrad Shultz
On 11/8/11 1:14 PM, Jeffrey Oleander wrote:
>> In order to respond to both a single and double tap, do I
>> thus need to attach two gesture recognizers?
> 
> Go another layer more primitive:

Please don't drop down to UITouch unless you have to (which mainly means
if you are supporting pre-UIGestureRecognizer devices).

As for your issue of single vs. double taps, from the class reference:

"For the gesture to be recognized, the specified number of fingers must
tap the view a specified number of times."

I'm not sure why you aren't receiving intermediate messages, but trying
to key off intermediates is not a great pattern anyway.  Just attach two
gesture recognizers, then you have the benefit of separating your action
methods (which will be nice if you decide to change gestures later on).

If you want to suppress the single tap action in the event of a double
tap, employ the –requireGestureRecognizerToFail: method when setting up
the recognizers, paying special attention to the notes ("Requiring a
Gesture Recognizer to Fail") on this matter in the Event Handling Guide
(http://developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizers/GestureRecognizers.html).

-- 
Conrad Shultz

Synthetiq Solutions
www.synthetiqsolutions.com
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: UITapGestureRecognizer and state/action w/rt numberOfTapsRequired

2011-11-08 Thread Ben Kennedy
On 08 Nov 2011, at 1:14 pm, Jeffrey Oleander wrote:

>> In order to respond to both a single and double tap, do I
>> thus need to attach two gesture recognizers?
> 
> Go another layer more primitive:

Yeah, I may end up just doing that.  I wanted to use gesture recognizer(s) so 
that my containing view controller can attach them as required (to 
subview.gestureRecognizers) without needing to burden the subview with logic 
that's otherwise outside its scope.

cheers,

-b

--
Ben Kennedy, chief magician
Zygoat Creative Technical Services
http://www.zygoat.ca

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: UITapGestureRecognizer and state/action w/rt numberOfTapsRequired

2011-11-08 Thread Jeffrey Oleander
> From: Ben Kennedy 
> Subject: UITapGestureRecognizer and state/action w/rt numberOfTapsRequired
> To: "Cocoa-Dev List" 
> Date: Tuesday, 2011 November 8, 14:56
> 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?

Go another layer more primitive:

http://www.oreillynet.com/pub/a/iphone/excerpts/iphone-programming-user/touch-patterns.html

http://iphonedevelopertips.com/user-interface/detect-single-tap-in-uiscrollview.html

http://developer.apple.com/library/ios/documentation/UIKit/Reference/UITouch_Class/Reference/Reference.html#//apple_ref/occ/instp/UITouch/tapCount

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


UITapGestureRecognizer and state/action w/rt numberOfTapsRequired

2011-11-08 Thread Ben Kennedy
>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, or has behaviour changed since it was written?

cheers,

-b

--
Ben Kennedy, chief magician
Zygoat Creative Technical Services
http://www.zygoat.ca

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com