Re: detecting touch and hold vs touch in UIButton
Re: detecting touch and hold vs touch in UIButton
- Subject: Re: detecting touch and hold vs touch in UIButton
- From: Scott Andrew <email@hidden>
- Date: Sun, 6 Jun 2010 11:04:14 -0700
You still need that timer. Especially for non 3.2. If you get your touchEnded before your timer is reached it was just a tap.
Scott
Sent from my iPad
On Jun 6, 2010, at 8:54 AM, Alejandro Marcos Aragón <email@hidden> wrote:
> Hi Matt,
>
> Thanks for your answer. Still, I don't think that solves the problem. It is not just the difference in time what matters. If the user just taps the button, a UISegmentedControl appears, thus this target is in touch up inside. Now, if the user taps and holds, another type of control appears after a delay so this has to be done in touch down (because the user is still holding), and the user should stop holding the button when the new control appears.
>
> In your approach, everything is done in the userDidTouchUp, but the tap and hold control should appear even if the user didn't stop holding. If you have a better solution, please let me know, again thanks for your answer.
>
> aa
>
>
> On Jun 6, 2010, at 9:35 AM, Matt Neuburg wrote:
>
>> On Sat, 05 Jun 2010 21:34:48 -0700, Matt Neuburg <email@hidden> said:
>>> On Fri, 4 Jun 2010 21:16:50 -0500, Alejandro Marcos Arag?n
>>> <email@hidden> said:
>>>> I've been trying to detect touch and hold vs touch on a subclass of UIButton.
>>>
>>> I think you want to imitate Listing 3-3 of Event Handling in the iPhone
>>> Application Programming Guide, handling the touches yourself. m.
>>
>> Okay, forget that answer. :) If the difference between touch and
>> touch-and-hold is just a matter of how long the time is between the touch
>> down and the touch up, then all you have to do is measure that time:
>>
>> - (void) userDidTouchDown: (id) sender event: (UIEvent*) e {
>> downtime = [e timestamp]; // downtime is an ivar or global
>> }
>>
>> - (void) userDidTouchUp: (id) sender event: (UIEvent*) e {
>> double diff = [e timestamp] - downtime;
>> if (diff < 0.2) NSLog(@"tap");
>> else NSLog(@"tap and hold");
>> }
>>
>> Obviously Touch Down is targeted at userDidTouchDown:. I think you might
>> want to target both Touch Up Inside and Touch Up Outside at userDidTouchUp:.
>>
>> If you mean something more complex and profound by the difference between
>> touch and touch-and-hold, you can probably figure it out from the UIEvent,
>> so you'd do some more complex and profound form of event tracking here.
>>
>> Anyway, I apologize for being hasty and not very clear before. What I was
>> really trying to say was that all your addition and removal of target-action
>> pairs seems unnecessary.
>>
>> m.
>>
>> --
>> matt neuburg, phd = email@hidden, <http://www.tidbits.com
>>
>
> _______________________________________________
>
> 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
_______________________________________________
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