2010-11-25 43 views
0

我有按鈕事件。如果單擊(觸摸)按鈕我正在做翻轉動作。如果雙擊按鈕,我正在做另一個未隱藏的操作按鈕。兩個相同的按鈕event.i嘗試圖像觸摸,但沒有得到。如何找到單擊或雙擊按鈕。如何實現定時器找到觸摸任何樣本或教程..如何使用定時器在按鈕上找到觸摸

回答

2

這可能讓你開始..

(我用0.5的超時值,但你可能想改變這種)

-(void)butonEvent:(id)sendr{ 


    if(buttonTimer)[self doublePress]; 
    else 
    { 

    //buttonTimer is a local NSTimer 

    buttonTimer = [NSTimer scheduledTimerWithTimeInterval: 0.5 
        target: self 
        selector: @selector(handleTimer:) 
        userInfo: nil 
        repeats: NO]; 
    } 

    } 


    -(void)singlePress{ 
[buttonTimer invalidate];buttonTimer=nil;//edit 
    NSLog(@"Single Press"); 
    } 

    -(void)doublePress{ 
[buttonTimer invalidate];buttonTimer=nil;//edit 
    NSLog(@"doublePress"); 
    } 

    -(void)handleTimer:(id)sendr 
    {   
    [self singlePress]; 
    } 
+0

我遇到問題雙擊。其採取雙重行動,以及單後集itme – SOF 2010-11-25 16:42:01

+0

固定與編輯 – 2010-11-25 16:52:03

2

有一個在UIButton的活動兩個選項,

您可以使用下面的檢測, 單點觸摸通過的TouchDown, 雙觸摸過TouchDownRepeat。 您可以像使用TouchUpInside一樣使用IB相同的方式連接您的UIButtons,並編寫適合您的編碼。