我與多點觸控工作,而寫作過程UITouches,所以基本上我做的是,我有手支撐寫作,因爲通常情況下,它是如何的用戶寫道,我跟着這個鏈接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;
}
在觸摸感動,我將只需要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;
}
}
感動代碼供您參考這裏是分別用單點觸摸和多點觸摸書寫的圖像
你可以看到,當我與單點觸摸寫,我的文筆流暢,曲線是平滑的,但是當我的手休息寫的,我的曲線得到鋸齒狀的,因爲你可以在第二圖像中看到。
因此,朋友們,請幫我出
我認爲,跟蹤觸摸有什麼問題,這就是爲什麼它與它混合 – Ranjit
也許你可以嘗試檢測用戶的休息手的位置,並禁用該區域的觸摸?一旦用戶開始繪畫,爲什麼不在'touchesEnded:'和'touchesCancelled:'之前忽略那些不接觸的觸摸? –
你好@AaronBrager,謝謝你的回覆,正如你所看到的,我已經找到了跟蹤觸摸,並且忽略了基於更高y值的觸摸的其餘部分,觸摸開始了。你的意思是在touchesEnded之前忽略接近觸摸的同一件事:觸及取消:請糾正我,如果我錯了。 – Ranjit