触摸结束未被调用 [英] Touches Ended not being called

查看:103
本文介绍了触摸结束未被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在努力识别iOS应用程序中的触摸,并且我有这个简单的代码

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);
 }];
}

touchesBegan很好,如果我同时从1根手指到5根手指放在屏幕上,我会看到它以正确的信息被调用

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

touchesBegan不会发生同样的情况,很多时候,如果我在屏幕上有3个手指并同时移开它们,我只会看到2次触摸结束的信息(有时甚至是1个).如果我一次伸出一根手指,该方法通常也会被调用2次(有时为1次,尽管很少会被称为正确的3次). 随着触摸次数的增加,touchesEnded方法中未显示某些信息的可能性也很明显

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

方法touchesMoved:withEvent:touchesCancelled:withEvent:也以相同的逻辑实现

Methods touchesMoved:withEvent: and touchesCancelled:withEvent: are also implemented, with the same logic

有人可以解释这种行为吗?有什么我想念的吗?

Can someone explain this behavior? Is there something I'm missing?

推荐答案

您必须在Swift中设置recognizer.cancelsTouchesInView = false或在Objective-C中设置recognizer.cancelsTouchesInView = NO;

You'd have to set recognizer.cancelsTouchesInView = false in Swift or recognizer.cancelsTouchesInView = NO; in Objective-C

这篇关于触摸结束未被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆