开发者

How do I stop multiple UIButton pressing?

开发者 https://www.devze.com 2023-01-13 10:17 出处:网络
Imagine I have a UIView and to that I add 2 UIButtons. I find that I can put a finger on one button, then开发者_高级运维, holding the first, I can touch the 2nd button with another finger. Both butto

Imagine I have a UIView and to that I add 2 UIButtons.

I find that I can put a finger on one button, then开发者_高级运维, holding the first, I can touch the 2nd button with another finger. Both buttons will show their UIControlStateHighlighted images.

Is there a way to stop the 2nd touch working? I thought that multipleTouchEnabled = NO was the answer, but seems not!

Any ideas?


use a property of UIButton called exclusiveTouch


-(IBAction)button1Pressed {
    button2.enabled = NO;
}
-(IBAction)button2Pressed {
    button1.enabled = NO;
}

For touch down.

Then for touch up inside and touch up outside.

-(IBAction)button1Lifted {
    button2.enabled = YES;
}
-(IBAction)button1Lifted {
    button2.enabled = YES;
}


when you tab on 1st button, in Button's IBAction method,make a user interaction of a 2nd button disabled.(On 1st line) and in last line of 1st button IBAction code, make 2nd button user interaction enabled.(on last line). set IBAction to touchDown.

& vice-versa.


add this property to each button\n button.exclusiveTouch=YES;

0

精彩评论

暂无评论...
验证码 换一张
取 消