• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: detecting touch and hold vs touch in UIButton
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: detecting touch and hold vs touch in UIButton


  • Subject: Re: detecting touch and hold vs touch in UIButton
  • From: Matt Neuburg <email@hidden>
  • Date: Sun, 06 Jun 2010 09:11:05 -0700
  • Thread-topic: detecting touch and hold vs touch in UIButton

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

  • Follow-Ups:
    • Re: detecting touch and hold vs touch in UIButton
      • From: Alejandro Marcos Aragón <email@hidden>
References: 
 >Re: detecting touch and hold vs touch in UIButton (From: Alejandro Marcos Aragón <email@hidden>)

  • Prev by Date: AUTO: Bill Abt is out of the office. (returning 06/14/2010)
  • Next by Date: changing NSTextView text colour
  • Previous by thread: Re: detecting touch and hold vs touch in UIButton
  • Next by thread: Re: detecting touch and hold vs touch in UIButton
  • Index(es):
    • Date
    • Thread