2011-09-26 31 views
0
UIGraphicsBeginImageContext(self.view.bounds.size); 
     [currentStrokeImageView.image drawInRect:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)]; 
     CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); 
     CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeNormal); 
     CGContextSetLineWidth(UIGraphicsGetCurrentContext(), dWidth); 
     CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), r, g, b, 1.0f); 
     CGContextBeginPath(UIGraphicsGetCurrentContext()); 
     CGContextMoveToPoint(UIGraphicsGetCurrentContext(), pointA.x, pointA.y); 
     CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), pointB.x, pointB.y); 
     CGContextStrokePath(UIGraphicsGetCurrentContext()); 
     currentStrokeImageView.image = UIGraphicsGetImageFromCurrentImageContext(); 
     UIGraphicsEndImageContext(); 

由於某些原因,這款產品在iphone/ipod上絕對沒有延遲,但在iPad上它們在繪製時顯着滯後。我使用的代碼在上面,有任何建議來解決這個問題?Coregraphics在iPad上造成很大的延遲?

+1

這將有助於瞭解上述代碼正在執行的上下文(rimshot!)。 –

+0

你在什麼情況下意味着什麼?當用戶拖動手指時,它位於self.view內,請詳細說明,因爲我不太清楚你的意思(初學者的類型) – Aspyn

+0

這種代碼被調用的方法是什麼? –

回答

3

之所以這麼落後,是因爲你在做touchesMoved:withEvent:。當接收到觸摸事件時,該方法可以被調用很多次(顯然)。因爲繪製到圖形上下文可能是一項資源密集型操作,所以我會建議您使用而不是來處理您在那裏做的所有事情。我會盡可能將您正在執行的渲染延遲至touchesBegintouchesEnd方法。如果這是不可能的,也許你只能在運動中達到一定的三角洲時才能執行這些操作,例如,每點。

+0

我會嘗試它... – Aspyn

+0

我已經嘗試了三角洲方法(使用距離公式)和試圖讓這個工作的計時器方法。 delta方法的問題是移動的觸摸總是至少有一個,所以對於精確繪製,delta方法不會改變任何東西。使用定時器方法,它不會更新足夠的時間,並且不夠快,無法跟上觸摸(甚至是250.0f/1.0f,300.0f/1.0f)。所以你知道任何其他的解決方案。感謝前兩個,但如果你知道另一個請回復 – Aspyn