0

我正在尝试从 iOS 4.2 示例“Touches”发展,但我做不到(我是 iOS 新手):我想计算每个不同 UIImageViews 上的点击次数。目前,无论我在哪里按,在视图中,在 UIImageView(s) 之外等,样本计数都会点击。我想要的是显示我在特定 UIImageView 内点击了多少次点击。
输出将是一个标签,说7 taps on the red button; 2 taps on the yellow button; 3 taps on the green.

4

1 回答 1

1

好,我知道了:

NSUInteger touchCount = 0;
for (UITouch *touch in touches) {
    if(numTaps >= 2) {
        CGPoint touchPoint = [touch locationInView:self];
        if (CGRectContainsPoint([firstTapView frame], touchPoint)) {
            firstTapView.text = [NSString stringWithFormat:@"%d",numTaps];
        } else if (CGRectContainsPoint([secondTapView frame], touchPoint)) {
            secondTapView.text = [NSString stringWithFormat:@"%d",numTaps];
        } else if (CGRectContainsPoint([thirdTapView frame], touchPoint)) {
            thirdTapView.text = [NSString stringWithFormat:@"%d",numTaps];
        } 

    }

    touchCount++;  
}   

其中 firstTapView、secondTapView 和 thirdTapView 是我的 UILabel,显示在屏幕上。Touches 示例使用 UIImageView,但我将其更改为 UILabel,因此我可以在触摸屏幕的同时进行书写。

于 2011-01-10T16:28:38.633 回答