1

我在 iPhone 应用程序中有一个 X 按钮。

单击它一次会使 X 按钮变为红色。再次单击它(在 X 按钮变为红色之后)执行取消操作。

但是,如果有人单击 X 按钮(现在是红色)并且在X 按钮之外单击,我希望它恢复到原来的状态。

我该怎么做?

4

1 回答 1

1

检查按钮外部是否有触摸。如果button.isRed == TRUE,那么你应该取消它。希望它足够清楚。

说你有UIButton *closeButton。代码将是这样的:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [super touchesBegan:touches withEvent:event];
    if ([touches anyObject].view == closeButton){
        //User touched in the button!
    } else {
        //User touched outside the button
    }
}

让我知道它是否有效。

于 2013-10-05T17:33:33.023 回答