Skip to content

Instantly share code, notes, and snippets.

@Air-Craft
Created April 24, 2014 09:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Air-Craft/770e6ac5097a6c67d3ac to your computer and use it in GitHub Desktop.
Save Air-Craft/770e6ac5097a6c67d3ac to your computer and use it in GitHub Desktop.
Quick snippet for actioning touches by touch down index, i.e. in sequence
// DNF: @implementation { NSMutableArray *_activeTouches }
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch *t in touches) {
NSUInteger idx = _activeTouches.count;
[_activeTouches addObject:t];
[self _updateForTouch:t withIndex:idx];
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch *t in touches) {
NSUInteger idx = [_activeTouches indexOfObject:t];
[self _updateForTouch:t withIndex:idx];
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[_activeTouches removeObjectsInArray:touches.allObjects];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[_activeTouches removeObjectsInArray:touches.allObjects];
}
- (void)_updateForTouch:(UITouch *)touch withIndex:(NSUInteger)touchIdx
{
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment