防止同时触摸多个按钮

发布于 2024-09-14 05:54:34 字数 69 浏览 7 评论 0原文

在iOS中,是否有办法防止包含多个按钮(兄弟)的UIView同时被触摸?例如,可以通过两次触摸同时点击两个并排的不重叠按钮。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

叹倦 2024-09-21 05:54:34

设置 UIView.exclusiveTouch。

Set UIView.exclusiveTouch.

别低头,皇冠会掉 2024-09-21 05:54:34

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

例如,

[Button1 setExclusiveTouch:YES];

[Button2 setExclusiveTouch:YES];

viewDidLoadviewWillAppear 中设置此方法

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

我只土不豪 2024-09-21 05:54:34

斯威夫特 4 语法:

    buttonA.isExclusiveTouch = true
    buttonB.isExclusiveTouch = true

Swift 4 Syntax:

    buttonA.isExclusiveTouch = true
    buttonB.isExclusiveTouch = true
金橙橙 2024-09-21 05:54:34
for(UIView* v in self.view.subviews)
    {
    if([v isKindOfClass:[UIButton class]])
    {
        UIButton* btn = (UIButton*)v;
        [yourButton setExclusiveTouch:YES];
    }
}
for(UIView* v in self.view.subviews)
    {
    if([v isKindOfClass:[UIButton class]])
    {
        UIButton* btn = (UIButton*)v;
        [yourButton setExclusiveTouch:YES];
    }
}
恋竹姑娘 2024-09-21 05:54:34

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

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

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.

func exclusiveTouchForButtons(view: UIView) {
    for cmp in view.subviews {
        if let cmpButton = cmp as? UIButton {
            cmpButton.exclusiveTouch = true
        } else {
            exclusiveTouchForButtons(cmp)
        }
    }
}
咽泪装欢 2024-09-21 05:54:34
I have tried both  multiTouchEnabled and exclusiveTouch but unfortunately 
none of them workout for me.I have tried the following code worked 
perfectly.

在 .h 文件中设置此代码

BOOL ClickedBool;

在方法开始处设置以下代码。

if(ClickedBool==TRUE)
{
     return;
}
else
{
    ClickedBool=TRUE;
}
I have tried both  multiTouchEnabled and exclusiveTouch but unfortunately 
none of them workout for me.I have tried the following code worked 
perfectly.

Set this code at .h file

BOOL ClickedBool;

Set the following code at method start.

if(ClickedBool==TRUE)
{
     return;
}
else
{
    ClickedBool=TRUE;
}
云柯 2024-09-21 05:54:34

要启用独占触摸,您需要为每个元素设置属性 isExclusiveTouch

myView.isExclusiveTouch = true

如果您希望更改默认行为,可以使用 UIView 类的 UIAppearance。

UIView.appearance().isExclusiveTouch = true

To enable the exclusive touch you need to set the property isExclusiveTouch for each element.

myView.isExclusiveTouch = true

If you would want that the default behaviour changes you could use the UIAppearance of the UIView class.

UIView.appearance().isExclusiveTouch = true
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文