2011-04-09 129 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