2013-05-03 52 views
1

是否可以在用戶點擊時禁用uibutton?在按下時禁用了uibutton?

我使用NBTouchAndHoldButton並在我的方法中我希望在達到某個數字時禁用按鈕。

//...... 
    [touchAndHoldButton addTarget:self action:@selector(countNumbers:) forTouchAndHoldControlEventWithTimeInterval:0.2]; 

//..... 

-(void) countNumbers { 

[self countTheNumbers]; 

if (currentNumber == 10) { 
     touchAndHoldButton.userInteractionEnabled = NO; 

     } 

} 

所以當按住該按鈕,當到達10號我想按鈕被禁用,從這一點上忽略觸摸。在上面的例子中,按鈕仍然接收來自用戶的輸入,直到用戶擡起手指。然後它進入禁用狀態。 這可能嗎?

+0

其中的近況數量的整數遞增,當你觸摸的數量應以1遞增,那麼只有條件不良的工作, – Purva 2013-05-03 03:32:49

回答

0
//.......... 

[self.btnObj addTarget:self action:@selector(countNumbers) forTouchAndHoldControlEventWithTimeInterval:0.2]; 

//.............. 

-(void) countNumbers { 
    if (currentNumber == 10) { 
     self.btnObj.userInteractionEnabled = NO; 
     return; 
    } 
    [self countTheNumbers]; 
} 
-(void)countTheNumbers{ 
    currentNumber++; 
} 

試試這個。希望它能幫助到您。

0

假設你正在使用NBTouchAndHoldButton請訪問:https://github.com/balazsnemeth/NBTouchAndHoldButton

在 「NBTouchAndHoldButton.h」 你需要暴露holdTimer屬性:

@property (strong, nonatomic) NSTimer* holdTimer; 

比,在 「NBTouchAndHoldButton.m」,你需要原創holdTimer聲明並同步全新創建的屬性:

//NSTimer* holdTimer; 
@synthesize holdTimer; 

這樣你c每當你的代碼達到指定的標準時,該計時器就會失效。假設你按鈕名稱爲btnStartAnimation,所有你需要做的是:

[btnStartAnimation.holdTimer invalidate];