我正在努力识别iOS应用程序中的触摸,我有这个简单的代码
- (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);
}];
}
Run Code Online (Sandbox Code Playgroud)
touchesBegan被称为罚款,如果我同时从屏幕上的1个手指放到5个手指,我看到它被正确的信息调用
同样的情况不会发生touchesBegan,很多时候如果我在屏幕上有3个手指并同时移除它们,我只看到2个触摸的信息被结束(有时甚至1个).如果我一次取出一个手指,该方法通常也会被调用2次(有时为1次,虽然很少会被称为正确的3次)随着触摸次数的增加,一些信息的可能性也不大在touchesEnded方法中显示
方法touchesMoved:withEvent:和touchesCancelled:withEvent:同样实施,同样的逻辑
有人可以解释这种行为吗?有什么我想念的吗?