如何禁用8个按钮的多点触控3? Xcode中

时间:2014-05-23 18:14:54

标签: ios objective-c xcode button

我有8个按钮,我想这样做:点击其中一个按钮时将显示为灰色,其中三个按钮处于活动状态。但是当我按住按钮时会发生这种情况,但不要推动按钮。如果在按钮上移动手指并按下它,则所有按钮都将处于活动状态。我尝试使用" exclusiveTouch"但它变为非活动的所有7个按钮。

代码:

- (void)viewDidLoad
{
    qsq.exclusiveTouch = YES;
    qsq2.exclusiveTouch = YES;
    qsq3.exclusiveTouch = YES;
    qsq4.exclusiveTouch = YES;
    qsq_plr2.exclusiveTouch = YES;
    qsq2_plr2.exclusiveTouch = YES;
    qsq3_plr2.exclusiveTouch = YES;
    qsq4_plr2.exclusiveTouch = YES;
}

当我点击" qsq"然后所有按钮都无效。但我需要qsq2,qsq3,qsq4变为非活动状态,其他按钮处于活动状态。

1 个答案:

答案 0 :(得分:0)

看起来你的设计比基本UIView属性可以处理的要复杂一些。这是解决方案的一个示例,仅使用2个按钮。

设定:

[button1 addTarget:self action:@selector(disableButtons:) forControlEvents:UIControlEventTouchDown];
[button1 addTarget:self action:@selector(reenableButtons:) forControlEvents:UIControlEventTouchUpInside|UIControlEventTouchUpOutside|UIControlEventTouchCancel];
[button2 addTarget:self action:@selector(disableButtons:) forControlEvents:UIControlEventTouchDown];
[button2 addTarget:self action:@selector(reenableButtons:) forControlEvents:UIControlEventTouchUpInside|UIControlEventTouchUpOutside|UIControlEventTouchCancel];

在回调中,您禁用了需要禁用的按钮:

-(void) disableButtons:(UIButton*)button {

    if (button == button1) {
        button2.enabled = FALSE;
    } else if (button == button2) {
        button1.enabled = FALSE;
    }
}

-(void) reenableButtons:(UIButton*)button {

    if (button == button1 || button == button2) {
        button1.enabled = TRUE;
        button2.enabled = TRUE;
    }
}