Double tap on a button

耗尽温柔 提交于 2019-12-19 04:10:31

问题


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;)



来源:https://stackoverflow.com/questions/5608006/double-tap-on-a-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!