双击按钮

Raf*_*ael 3 iphone xcode action ipad

如何在我的按钮上添加双击操作?

Rav*_*vin 11

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

  • 要注册此事件,请调用`[control addTarget:self action:@selector(buttonTouchDownRepeat:event :) forControlEvents:UIControlEventTouchDownRepeat];` (3认同)

Ole*_*ann 5

在IB或代码中,将操作连接到按钮的UIControlEventTouchDownRepeat事件.action方法应该有这样的签名:

- (void) buttonTouchDownRepeat:(id)sender event:(UIEvent *)event
Run Code Online (Sandbox Code Playgroud)

在方法的实现中,您可以访问UITouch实例,[[event allTouches] anyObject]然后检查触摸的tapCount值.