This is a simple problem, but tricky to solve.
这是一个简单的问题,但很难解决。
I have two buttons that perform the same function.
我有两个执行相同功能的按钮。
I've set different touch events for the buttons. Although this helps, it's still possible to press them simultaneously. On a slow connection, it will be even easier.
我为按钮设置了不同的触摸事件。尽管这很有帮助,但仍然有可能同时按压它们。在慢速连接上,会更容易。
[vote1Btn addTarget:self action:@selector(voteUp:) forControlEvents:UIControlEventTouchUpInside];
[vote2Btn addTarget:self action:@selector(voteUp:) forControlEvents:UIControlEventTouchDown];
2 个解决方案
#1
22
Set the exclusiveTouch
property of both buttons to YES.
将两个按钮的exclusive sivetouch属性设置为YES。
If that isn't enough, have each button call the shared application object's beginIgnoringInteractionEvents
when its operation starts and call endIgnoringInteractionEvents
when its operation ends.
如果这还不够,让每个按钮在操作开始时调用共享应用程序对象的beginIgnoringInteractionEvents,并在操作结束时调用endIgnoringInteractionEvents。
#2
0
for(UIView* v in self.view.subviews)
{
if([v isKindOfClass:[UIButton class]])
{
UIButton* btn = (UIButton*)v;
[yourButton setExclusiveTouch:YES];
}
}
this will work!
这将工作!
#1
22
Set the exclusiveTouch
property of both buttons to YES.
将两个按钮的exclusive sivetouch属性设置为YES。
If that isn't enough, have each button call the shared application object's beginIgnoringInteractionEvents
when its operation starts and call endIgnoringInteractionEvents
when its operation ends.
如果这还不够,让每个按钮在操作开始时调用共享应用程序对象的beginIgnoringInteractionEvents,并在操作结束时调用endIgnoringInteractionEvents。
#2
0
for(UIView* v in self.view.subviews)
{
if([v isKindOfClass:[UIButton class]])
{
UIButton* btn = (UIButton*)v;
[yourButton setExclusiveTouch:YES];
}
}
this will work!
这将工作!