質問

iOS 4.2のサンプル「タッチ」から進化しようとしていますが、それはできません(iOSは初めてです):それぞれの異なるuiimageViewsのタップをカウントしたいと思います。現在、サンプルカウントは、どこに押し付けても、ビュー、UIIMAGEVIEW(S)などの外側などを押し付けています。私が望むのは、特定のUIIMAGEView内でタップをタップしているタップの数を示すことです。
出力はラベルの言うものです 7 taps on the red button; 2 taps on the yellow button; 3 taps on the green.

役に立ちましたか?

解決

はい、分かりました:

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は、画面に表示されている私のuilabelsです。タッチサンプルはuiimageviewを使用しますが、Uilabelに変更したので、画面に触れながら書くことができます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top