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: Alejandro Marcos Aragón <email@hidden>
- Date: Sun, 6 Jun 2010 13:08:39 -0500
Hi Matt, thanks for clarifying that. That worked like a charm! I had to override functions:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
But it works just as I want. Thanks again!
aa
On Jun 6, 2010, at 11:11 AM, Matt Neuburg wrote:
> On or about 6/6/10 8:54 AM, thus spake "Alejandro Marcos Aragón"
> <email@hidden>:
>
>> 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.
>
> Okay, so obviously you then also use performSelector as you were doing,
> because you have to respond a certain amount of time after the touch starts
> if the touch has not ended. But you still don't need to add and remove
> target-action pairs.
>
>
> - (void) tapAndHold {
> NSLog(@"respond to tap and hold");
> }
>
> - (void) userDidTouchDown: (id) sender event: (UIEvent*) e {
> downtime = [e timestamp];
> [self performSelector:@selector(tapAndHold) withObject:nil
> afterDelay:0.4];
> }
>
> - (void) userDidTouchUp: (id) sender event: (UIEvent*) e {
> double diff = [e timestamp] - downtime;
> if (diff < 0.3) {
> [[self class] cancelPreviousPerformRequestsWithTarget:self];
> NSLog(@"respond to tap");
> }
> }
>
> The numbers are up to you, of course. m.
>
> --
> matt neuburg, phd = email@hidden, http://www.tidbits.com/matt/
> pantes anthropoi tou eidenai oregontai phusei
> Among the 2007 MacTech Top 25, http://tinyurl.com/2rh4pf
> AppleScript: the Definitive Guide, 2nd edition
> http://www.tidbits.com/matt/default.html#applescriptthings
> Take Control of Exploring & Customizing Snow Leopard
> http://tinyurl.com/kufyy8
> RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
> TidBITS, Mac news and reviews since 1990, 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