How can I add an action for a double tap on my button?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
- (void) buttonTouchDownRepeat:(id)sender event:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
if(touch.tapCount == 2) {
NSLog(@"Twice");
}
else {
NSLog(@"otherwise");
}
}
回答2:
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.
回答3:
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;)