2012-11-21 27 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;