detecting touch and hold vs touch in UIButton
detecting touch and hold vs touch in UIButton
- Subject: detecting touch and hold vs touch in UIButton
- From: Alejandro Marcos Aragón <email@hidden>
- Date: Fri, 4 Jun 2010 21:16:50 -0500
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