Button presses simultaneously

This is a simple problem, but a difficult task.

I have two buttons that perform the same function.

I set different touch events for the buttons. Although this helps, you can still click them at the same time. With a slow connection, it will be even easier.

[vote1Btn addTarget:self action:@selector(voteUp:) forControlEvents:UIControlEventTouchUpInside];
[vote2Btn addTarget:self action:@selector(voteUp:) forControlEvents:UIControlEventTouchDown];
+5
source share
2 answers

Set the property exclusiveTouchfor both buttons to YES.

If this is not enough, ask each button to call the general application object beginIgnoringInteractionEventswhen it starts working, and call endIgnoringInteractionEventswhen its action ends.

+21
source
for(UIView* v in self.view.subviews)
{
    if([v isKindOfClass:[UIButton class]])
    {
        UIButton* btn = (UIButton*)v;
        [yourButton setExclusiveTouch:YES];
    }
}

it will work!

0
source

All Articles