开发者

Double tap on a button

How can I add an action开发者_StackOverflow社区 for a double tap on my button?


- (void) buttonTouchDownRepeat:(id)sender event:(UIEvent *)event {
    UITouch *touch = [[event allTouches] anyObject];
    if(touch.tapCount == 2) {
        NSLog(@"Twice");
    }
    else {
        NSLog(@"otherwise");
    }
}


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜