I've playing around with recognizing the touches in an iOS Application, and I have this simple code
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"%lu",(unsigned long)[touches count]);
[touches enumerateObjectsUsingBlock:^(id obj, BOOL *stop) {
UITouch *touch = obj;
CGPoint touchLocation = [touch locationInNode:self.scene];
NSLog(@"B x:%f - y:%f",touchLocation.x,touchLocation.y);
}];
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[touches enumerateObjectsUsingBlock:^(id obj, BOOL *stop) {
UITouch *touch = obj;
CGPoint touchLocation = [touch locationInNode:self.scene];
NSLog(@"E x:%f - y:%f",touchLocation.x,touchLocation.y);
}];
}
The touchesBegan is being called fine, if I place from 1 finger up to 5 fingers on the screen at the same time, I see it being called with the correct information
The same doesn't happen with touchesBegan
, many time if I have 3 fingers on the screen and remove them simultaneously, I only see information on 2 touches being ended (and sometimes even 1). If I take the fingers out one at a time, the method also usually gets called 2 times (sometimes 1, although rarely it will be called the correct 3 times)
As the number of touches increases, also the likely hood of some information not being shown in the touchesEnded
method
Methods touchesMoved:withEvent:
and touchesCancelled:withEvent:
are also implemented, with the same logic
Can someone explain this behavior? Is there something I'm missing?