gpt4 book ai didi

ios - Touches Ended 未被调用

转载 作者:技术小花猫 更新时间:2023-10-29 10:11:48 25 4
gpt4 key购买 nike

我一直在尝试识别 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);
}];
}

touchesBegan 被调用得很好,如果我同时将 1 到 5 个手指放在屏幕上,我会看到它被调用时包含正确的信息

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

方法touchesMoved:withEvent:touchesCancelled:withEvent:也实现了,逻辑相同

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

最佳答案

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

关于ios - Touches Ended 未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22127451/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com