2011-01-10 5 views
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이라는 레이블이됩니다.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로 변경 했으므로 화면을 터치하는 동안 작성할 수 있습니다.

관련 문제