Update the answer to clarify how multicasting works. your caption is incorrectly written - the correct order of handling touches is the following: all touches have a beginning and an end, an address that can be attached to a variable, all touches are entered into an array of touches touch to their variables.
The touchesEnded function starts always at the end of any touch, and the touchesBegan function starts. always starts at the beginning of the next touch.
declare variables UITouch * touch1; UITouch * touch2;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"began start"); //перебираем касания for (UITouch *touch in touches) { if (touch1 == nil) { NSLog(@"touch1 began"); touch1 = touch; } else if (touch2 == nil) { NSLog(@"touch2 began"); touch2 = touch; } } } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { for (UITouch *touch in touches) { if (touch == touch1) { NSLog(@"moved1"); } else if (touch == touch2) { NSLog(@"moved2"); } } } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { for (UITouch *touch in touches) { if (touch == touch1) { touch1 = nil; NSLog(@"ended1"); } else if (touch == touch2) { touch2 = nil; NSLog(@"ended2"); } } }
output result
began start
touch1 began first finger
began start
touch2 began second finger
moved1
moved1
moved2
ended1 let go first
moved2
ended2 let go of the second