gpt4 book ai didi

ios - 复杂的 iOS 多点触控交互 - 有什么建议吗?

转载 作者:行者123 更新时间:2023-11-28 17:40:30 25 4
gpt4 key购买 nike

我已经将已经处理单次触摸和拖动的 UIView 子类化。我想增强此 View 的交互性,以便在拖动时,如果用户用第二根手指触摸( View 中的任何其他位置),则系统会打印一条消息。我试了一下代码:

在我的头文件中我已经声明:

NSString *key; // This unique key identifies the first touch

我的 .m 文件:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{

for (UITouch *t in touches) {
if (key == NULL)
{
key = [[[NSValue valueWithPointer:t] description] copy];
}
if ([key isEqualToString:[[NSValue valueWithPointer:t] description]])
{
NSLog(@"calling parent to handle single touch");
[super touchesBegan:[NSSet setWithObject:t] withEvent:event];
}
else
{
[self twoTouchDetected];
}
}
}

-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch *t in touches) {
if ([key isEqualToString:[[NSValue valueWithPointer:t] description]])
{
[super touchesMoved:[NSSet setWithObject:t] withEvent:event];
}
}
}

-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UITouch *t in touches) {
if ([key isEqualToString:[[NSValue valueWithPointer:t] description]])
{
[super touchesEnded:[NSSet setWithObject:t] withEvent:event];
key = NULL;
}
}
}

不幸的是,此实现存在问题。第一次(用一根手指拖动时)如果我用第二根手指触摸,系统会立即注册。然而,我第二次用第二根手指触摸(同时仍然继续用第一根手指拖动),直到第一根手指抬起时,第二根手指的触摸才会记录下来。备份第二根手指的事件...

同样奇怪的是,有时,父级会收到来自第二根手指而不是第一根手指的触摸数据。

最佳答案

事实证明我的代码有效,但问题是我子类化了一个属于 Core Plot 框架的对象。这个框架对他们的对象做了奇怪的事情,因此触摸以错误的顺序返回。

我创建了一个空项目来接收触摸,一切都很顺利。

关于ios - 复杂的 iOS 多点触控交互 - 有什么建议吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8350435/

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