2011-01-10 4 views
0

私はiOS 4.2サンプルの "Touch"から進化しようとしていますが、私はそれを行うことはできません。私はiOSを初めて使っています。 それぞれのUIImageViewsのタップを数えたいと思います。現在のところ、サンプル数は、UIImageView(s)などのビューの外で、私がどこを押してもタップします。私が望むのは、特定のUIImageViewの内部でタップしているタップ数を表示することです。
出力は、7 taps on the red button; 2 taps on the yellow button; 3 taps on the greenというラベルになります。iOS - 特定のビュー内のタップ数を数える方法は?

+0

イメージ内のタップを検出することはできますか? – taskinoor

答えて

1

OK、私はそれを得た:firstTapView、secondTapViewとthirdTapViewが画面に表示されている私のUILabels、ある

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++; 
} 

。 TouchesサンプルはUIImageViewを使用していますが、UILabelに変更しましたので、画面に触れる間に書き込むことができます。

関連する問題