如何在多点触控序列中有效处理UITouches

我正在使用多点触控书写,所以基本上我正在做的是,我正在写手与支持,因为通常,它的用户如何写,我跟着这个链接如何忽略多点触控顺序中的某些UITouch点

一切都工作正常单触,但他们是一些问题,当我用手触摸屏幕,即多个UItouches写下面是我的代码

触摸开始,我经历了所有的触摸,我发现触摸与最高的位置,下面是我的代码

以下是我的代码

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch* topmostTouch = self.trackingTouch; for (UITouch *touch in touches) { ctr = 0; touchStartPoint1 = [touch locationInView:self]; if(!topmostTouch || [topmostTouch locationInView:self].y > touchStartPoint1.y) { topmostTouch = touch; pts[0] = touchStartPoint1; } } self.trackingTouch = topmostTouch; } 

在感动的时候,我只会采取self.trackingTouch,这是我触摸到的

我的触动移动下面的代码

 -(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { if(self.trackingTouch== nil) { return; } CGPoint p = [self.trackingTouch locationInView:self]; ctr++; pts[ctr] = p; if (ctr == 4) { pts[3] = midPoint(pts[2], pts[4]); self.currentPath = [[DrawingPath alloc] init]; [self.currentPath setPathColor:self.lineColor]; self.currentPath.pathWidth = [NSString stringWithFormat:@"%f",self.lineWidth]; [self.currentPath.path moveToPoint:pts[0]]; [self.currentPath.path addCurveToPoint:pts[3] controlPoint1:pts[1] controlPoint2:pts[2]]; [self setNeedsDisplay]; pts[0] = pts[3]; pts[1] = pts[4]; ctr = 1; } } 

这里的参考文献是分别用单点触摸和多点触控书写的图像

在这里输入图像说明

在这里输入图像说明

你可以看到,当我用单键写作的时候,我的写作是平滑的,曲线是平滑的,但是当我用手rest的时候,我的曲线变得锯齿状,就像你在第二幅图中看到的那样。

所以朋友们,请帮帮我

假设绘图代码完全相同,区别仅仅是处理额外触摸的额外开销。 循环处理这些,循环绘制,一切都至less翻了一番。所以,当你正在处理触摸,然后在手指#2上绘制,在这里在现实世界中,手指#1等仍然在移动…注意该UIKit只能在每个runLoop的末尾绘制。 我不认为有什么办法可以解决这个问题,就像我以前告诉过你的,我怀疑有很多人会重视能够多次触摸的能力,尽pipe这可能是我对澳大利亚有限的英语口语它。 祝你好运

我终于解决了我的问题,

这是代码

 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch* topmostTouch = self.trackingTouch; for (UITouch *touch in touches) { touchStartPoint1 = [touch locationInView:self]; if(!topmostTouch || [topmostTouch locationInView:self].y > touchStartPoint1.y) { ctr = 0; topmostTouch = touch; pts[0] = touchStartPoint1; } } self.trackingTouch = topmostTouch; } 

这个问题很简单,只需在检查里面设置ctr = 0就可以了。