Skip to content

Instantly share code, notes, and snippets.

@linktoming
Created December 19, 2011 07:10
Show Gist options
  • Save linktoming/1495829 to your computer and use it in GitHub Desktop.
Save linktoming/1495829 to your computer and use it in GitHub Desktop.
UIResponder's Touch Handling
#pragma mark -
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
messageLabel.text = @"Touches Began";
[self updateLabelsFromTouches:touches];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
messageLabel.text = @"Drag Detected";
[self updateLabelsFromTouches:touches];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
messageLabel.text = @"Touches Ended.";
[self updateLabelsFromTouches:touches];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
messageLabel.text = @"Touches Cancelled";
[self updateLabelsFromTouches:touches];
}
- (void)updateLabelsFromTouches:(NSSet *)touches {
NSUInteger numTaps = [[touches anyObject] tapCount];
NSString *tapsMessage = [[NSString alloc] initWithFormat:@"%d taps detected", numTaps];
tapsLabel.text = tapsMessage;
[tapsMessage release];
NSUInteger numTouches = [touches count];
NSString *touchMsg = [[NSString alloc] initWithFormat: @"%d touches detected", numTouches];
touchesLabel.text = touchMsg;
[touchMsg release];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment