2012-11-21 32 views
0

可能重複:
ios sdk stop multitouch functionality的iOS:如何避免多個按鈕調用共享功能的同時

我有一堆按鈕,它們都調用相同的功能。該功能包括按鈕本身的動畫。假設用戶點擊任何一個按鈕並獲得應該顯示的內容。但是,用戶有可能使用兩個手指並同時(或幾乎同時)觸摸兩個按鈕。在這種情況下,我看到兩個按鈕開始動畫。我怎樣才能限制一次只能調用一個按鈕。

回答

14
You can set exclusive touch to all buttons- 
[button setExclusiveTouch:YES]; 

看看iOS: setting Exclusive Touch to all buttons in a view

+0

這工作!非常感謝。接受你的答案。其他人的建議並不奏效,正如我在這裏發佈之前所測試的那樣。 –

1

BOOL的值設置爲YES。當你按下第一個按鈕。 並在動畫完成塊中將其設置爲NO。 並檢查BOOL調用動畫方法,如果BOOL爲YES,則不要調用第二個按鈕的動畫或刪除第一個按鈕的動畫並調用第二個方法的動畫。

@interface yourClass 
{ 
    BOOL animationStarted; 
} 
@end 

-(IBAction)click:(id)sender 
{ 
    if(!animationStarted) 
    { 
     animationStarted = YES; 
     //call the animation 
    } 
    else 
    { 
     //you can do two things here 
     //1.Skip the second button click 
     //2.Remove first button animation and start second button animation 
    } 
} 

在動畫完成塊:設置animationStarted = NO;