【发布时间】:2014-02-22 09:18:14
【问题描述】:
我在写作时使用多点触控,所以基本上我正在做的是,我正在用手支持写作,因为通常,它是用户写作的方式,我点击了这个链接How to ignore certain UITouch Points in multitouch sequence
单点触控一切正常,但当我用手触摸屏幕(即多个 UItouches)书写时,它们会出现问题 下面是我的代码
在触摸开始时,我遍历所有触摸,找到最高 y 位置的触摸,下面是我的代码
下面是我的代码
-(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;
}
在touches move.中,我只会拿self.trackingTouch,这是我在touches Began中找到的
我的触摸移动了下面的代码
-(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;
}
}
这里分别是单点触控和多点触控的书写图像供您参考
您可以看到,当我单点书写时,我的书写是平滑的,曲线是平滑的,但是当我用手搁置书写时,我的曲线会出现锯齿状,正如您在第二张图片中看到的那样。
朋友们,请帮帮我
【问题讨论】:
-
我认为,跟踪触摸出了点问题,这就是它搞砸的原因
-
也许您可以尝试检测用户静止手的位置,并禁用该区域的触摸?一旦用户开始绘图,为什么不直接忽略
touchesEnded:和touchesCancelled:之前不在该触摸附近的任何触摸? -
您好@AaronBrager,感谢您的回复,如您所见,我已经找到了跟踪触摸并忽略了基于更高值 y 的其余触摸,触摸开始。在 touchesEnded: 和 touchesCancelled: 之前忽略近距离触摸是不是同样的意思,如果我错了,请纠正我。
标签: ios core-graphics uitouch uibezierpath uiresponder