• 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: Alejandro Marcos Aragón <email@hidden>
  • Date: Sun, 6 Jun 2010 10:57:16 -0500

Hi Roland,

Thanks for answering my question. Shouldn't this be very restrictive though? I don't know the statistics, but I'm pretty sure that there is a large number of people having an old version of the OS.

aa

On Jun 5, 2010, at 10:04 PM, Roland King wrote:

> or if you are coding for 3.2 or later, use a UILongPressGestureRecognizer and let it do all the work.
>
> On 06-Jun-2010, at 12:36 AM, Scott Andrew wrote:
>
>> I believe the way to do this is to setup a timer on touchDown to fire once after X number of seconds. Your touchUp and touchCancelled should kill the timer if the timer is exists and is not invalidated. If you hit the timer you are being held. When the timer is hit you restart the timer again for the next check.
>>
>> Scott
>>
>>
>> On Jun 4, 2010, at 7:16 PM, Alejandro Marcos Aragón wrote:
>>
>>> Hi all,
>>>
>>> I've been trying to detect touch and hold vs touch on a subclass of UIButton. I basically accomplished that by doing the following:
>>>
>>> I first add the following when the button is created:
>>>
>>>
>>> 	[button addTarget:self action:@selector(sourceSelected:)
>>> 		forControlEvents:UIControlEventTouchUpInside];
>>> 	[button addTarget:self action:@selector(sourceTouchDown:)
>>> 		forControlEvents:UIControlEventTouchDown];
>>>
>>> Then in the functions:
>>>
>>> - (void) sourceSelected:(UIButton*) sender {
>>>
>>>
>>> 	// cancel request for extended meny
>>> 	[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(sourceSelectedExtended:) object:sender];
>>> 	...
>>> }
>>>
>>> - (void) sourceTouchDown:(UIButton*) sender {
>>>
>>> 	// give time before performing action
>>> 	[self performSelector:@selector(sourceSelectedExtended:) withObject:sender afterDelay:0.5];
>>> }
>>>
>>> - (void) sourceSelectedExtended:(UIButton*) sender {
>>>
>>> 	// remove action from button
>>> 	[sender removeTarget:self action:@selector(sourceSelected:) forControlEvents:UIControlEventTouchUpInside];
>>> 	...
>>> 	...
>>> 	// give time before performing action
>>> 	[self performSelector:@selector(addSourceAction:) withObject:sender afterDelay:1.];
>>>
>>> }
>>>
>>> - (void) addSourceAction:(UIButton*)sender {
>>>
>>> 	// remove action from button
>>> 	[sender addTarget:self action:@selector(sourceSelected:) forControlEvents:UIControlEventTouchUpInside];
>>>
>>> }
>>>
>>>
>>>
>>> Now, this works fine, but then I thought there must be an easier (and definitely more elegant) way to accomplish the same thing.
>>>
>>> Can someone through me a line here?
>>>
>>> Thank you all,
>>>
>>> aa
>>>
>>>
>>> _______________________________________________
>>>
>>> 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
>

_______________________________________________

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

References: 
 >detecting touch and hold vs touch in UIButton (From: Alejandro Marcos Aragón <email@hidden>)
 >Re: detecting touch and hold vs touch in UIButton (From: Scott Andrew <email@hidden>)
 >Re: detecting touch and hold vs touch in UIButton (From: Roland King <email@hidden>)

  • Prev by Date: Re: detecting touch and hold vs touch in UIButton
  • Next by Date: AUTO: Bill Abt is out of the office. (returning 06/14/2010)
  • 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