如何在多点触控序列中有效地处理UITouches [英] How to effectively process UITouches in a multitouch sequence
问题描述
我在写作时正在使用多点触控,所以基本上我正在做的是,我正在用手支持写作,因为通常,它是用户写的,我按照这个链接如何忽略多点触控序列中的某些UITouch积分
I am working with multitouch while writing, So basically what I am doing is, I am writing with hand support, because typically, its how user writes, I followed this link How to ignore certain UITouch Points in multitouch sequence
单手触摸时一切正常,但是当我用手触摸屏幕时,它们是一些问题,即多个UItouches
以下是我的代码
Everything is working fine with single touch, but their is some problem when I write with my hand touching the screen i.e multiple UItouches Below is my code
在触摸开始时,我经历了所有触摸,我发现触摸的y位置最高,下面是我的代码
In touches began, I go through all touches and I find the touch with highest y position, below is my code
以下是我的代码
-(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,我找到了触摸开始
In touches moved., I will only take self.trackingTouch, which I found in touches Began
我的动态下面的移动代码
My touches Moved code below
-(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;
}
}
以下是您的参考图像触摸和多点触控
For your reference here is the image of writing with single touch and multitouch respectively
你可以看到,当我用单点触摸书写时,我的书写很流畅,曲线很流畅,但是当我用手休息写字时,我的曲线变得锯齿状,正如你在第二张图片。
You can see that, when I write with single touch, my writing is smooth, the curves are smooth, but when I write with hand resting, I curves get jagged, as you can see in the second image.
所以朋友们,请帮帮我
推荐答案
我终于解决了我的问题,
I finally solved my issue,
这是代码
-(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,像这样......
The problem was very simple, just set ctr = 0 , inside the check, like this..
这篇关于如何在多点触控序列中有效地处理UITouches的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!