防止同时触摸多个按钮

时间:2022-10-30 08:46:46

In iOS is there anyway to prevent a UIView containing multiple buttons (siblings) from being simultaneously from being touched? For instance, two non-overlapping buttons that are side by side can be tapped at the same time with two touches.

在iOS中,无论如何都要防止同时触摸包含多个按钮(同级)的UIView?例如,可以在两次触摸的同时轻敲两个并排的非重叠按钮。

5 个解决方案

#1


91  

Set UIView.exclusiveTouch.

设置UIView.exclusiveTouch。

#2


11  

You can also use below method. If you have two buttons or more, to prevent multiple push at a time.

您也可以使用以下方法。如果您有两个或更多按钮,则一次防止多次按下。

for e.g,

例如,

[Button1 setExclusiveTouch:YES];

[Button2 setExclusiveTouch:YES];

Set this method in your viewDidLoad or viewWillAppear

在viewDidLoad或viewWillAppear中设置此方法

#3


2  

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

#4


1  

Swift 4 Syntax:

Swift 4语法:

    buttonA.isExclusiveTouch = true
    buttonB.isExclusiveTouch = true

#5


0  

You need to find all buttons on that view and set the "exclusiveTouch" property to true in order to prevent multi touch at the same time.

您需要找到该视图上的所有按钮并将“exclusiveTouch”属性设置为true,以便同时防止多点触摸。

func exclusiveTouchForButtons(view: UIView) {
    for cmp in view.subviews {
        if let cmpButton = cmp as? UIButton {
            cmpButton.exclusiveTouch = true
        } else {
            exclusiveTouchForButtons(cmp)
        }
    }
}

#1


91  

Set UIView.exclusiveTouch.

设置UIView.exclusiveTouch。

#2


11  

You can also use below method. If you have two buttons or more, to prevent multiple push at a time.

您也可以使用以下方法。如果您有两个或更多按钮,则一次防止多次按下。

for e.g,

例如,

[Button1 setExclusiveTouch:YES];

[Button2 setExclusiveTouch:YES];

Set this method in your viewDidLoad or viewWillAppear

在viewDidLoad或viewWillAppear中设置此方法

#3


2  

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

#4


1  

Swift 4 Syntax:

Swift 4语法:

    buttonA.isExclusiveTouch = true
    buttonB.isExclusiveTouch = true

#5


0  

You need to find all buttons on that view and set the "exclusiveTouch" property to true in order to prevent multi touch at the same time.

您需要找到该视图上的所有按钮并将“exclusiveTouch”属性设置为true,以便同时防止多点触摸。

func exclusiveTouchForButtons(view: UIView) {
    for cmp in view.subviews {
        if let cmpButton = cmp as? UIButton {
            cmpButton.exclusiveTouch = true
        } else {
            exclusiveTouchForButtons(cmp)
        }
    }
}