2014-02-22 21 views
2

我與多點觸控工作,而寫作過程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; 
    } 
} 

感動代碼供您參考這裏是分別用單點觸摸和多點觸摸書寫的圖像

enter image description here

enter image description here

你可以看到,當我與單點觸摸寫,我的文筆流暢,曲線是平滑的,但是當我的手休息寫的,我的曲線得到鋸齒狀的,因爲你可以在第二圖像中看到。

因此,朋友們,請幫我出

+0

我認爲,跟蹤觸摸有什麼問題,這就是爲什麼它與它混合 – Ranjit

+0

也許你可以嘗試檢測用戶的休息手的位置,並禁用該區域的觸摸?一旦用戶開始繪畫,爲什麼不在'touchesEnded:'和'touchesCancelled:'之前忽略那些不接觸的觸摸? –

+0

你好@AaronBrager,謝謝你的回覆,正如你所看到的,我已經找到了跟蹤觸摸,並且忽略了基於更高y值的觸摸的其餘部分,觸摸開始了。你的意思是在touchesEnded之前忽略接近觸摸的同一件事:觸及取消:請糾正我,如果我錯了。 – Ranjit

回答

1

假設繪圖代碼都是一樣的區別只是處理觸手可及的額外開銷。循環處理這些,循環繪製,一切都至少加倍。所以,當你正在處理觸摸,然後在#2手指上繪圖時,在這裏真實世界中,手指#1等仍然在移動......注意該UIKit只能在每個runLoop的末尾繪製。我認爲沒有任何辦法可以解決這個問題,正如我以前告訴過你的,我懷疑有很多人會重視能夠以多種方式進行繪製的能力,儘管這可能是我對澳大利亞有限的講英語的觀點它。祝你好運

+0

您好@Jef,感謝您的回覆,您是對的,我們需要智能地處理這些額外的觸摸,並且用戶將他的手放在屏幕上並書寫,我們不能指望用戶在沒有放下手的情況下在屏幕上書寫,因爲他/她通常會記筆記,所以根據我的說法,這是一個需要重視的重要問題。 – Ranjit

+0

你好@Jef,我認爲問題出在touchesBegan:function。說啥? – Ranjit

+0

你好@Jef,請幫我解決這個問題http://stackoverflow.com/questions/22033228/eraser-the-drawing-in-ios – Ranjit

0

我終於解決了我的問題,

下面是代碼

-(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,檢查裏面,這樣的..