I'm trying to evolve from the iOS 4.2 sample "Touches" but I can't do it (I'm new to the iOS): I'd like to count taps on each of the different UIImageViews. Currently the sample count taps no matter where I press, in the views, outside the UIImageView(s), etc. What I want is to show how many taps I'm tapping inside a specific UIImageView.
The output would be a label saying7 taps on the red button; 2 taps on the yellow button开发者_StackOverflow; 3 taps on the green
.OK I got it:
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++;
}
where firstTapView, secondTapView and thirdTapView are my UILabels, shown on the screen. Touches sample uses UIImageView, but I changed it to UILabel, so I can write whilst touching the screen.
精彩评论