2011-04-09 91 views

回答

5

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

- (void) buttonTouchDownRepeat:(id)sender event:(UIEvent *)event 

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

+0

我很noobie,更好的解释? – Rafael 2011-04-09 21:34:45

1

当然,如果你想成为超级StackOverFlow酷编程的奇才呢?然后使用UITapGestureRecognizer ...

授予它仅适用于iOS版最近,不要尝试在3.0;)

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

要注册此事件,请调用'[control addTarget:self action:@selector(buttonTouchDownRepeat:event :) forControlEvents:UIControlEventTouchDownRepeat];' – Urkle 2012-02-28 04:16:38

+0

我们能从这个函数中单击吗? – souvickcse 2014-09-24 07:20:11

+0

@souvickcse:'if(touch.tapCount == 1)' – 2014-09-27 08:43:47