Reputation: 83
How can I add an action for a double tap on my button?
Upvotes: 3
Views: 4697
Reputation: 8564
- (void) buttonTouchDownRepeat:(id)sender event:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
if(touch.tapCount == 2) {
NSLog(@"Twice");
}
else {
NSLog(@"otherwise");
}
}
Upvotes: 11
Reputation: 21760
Of course, if you want to be super StackOverFlow cool programming wiz? Then use UITapGestureRecognizer...
Granted it's only available for recent iOS, don't try it on 3.0;)
Upvotes: 1
Reputation: 135548
In IB or code, connect an action to the button's UIControlEventTouchDownRepeat
event. The action method should have a signature like this:
- (void) buttonTouchDownRepeat:(id)sender event:(UIEvent *)event
In the method's implementation, you can access a UITouch
instance with [[event allTouches] anyObject]
and then check the touch's tapCount
value.
Upvotes: 5