手指画的效率问题

我想开发一个应用程序来绘制触摸iPhone屏幕search如何做到这一点我已经find了一个示例配方(09-油漆)到第七章的埃里卡·萨申iPhone开发者食谱3.0代码示例 。 在这个例子中,你可以在这行下面看到,屏幕上的触摸被存储到一个NSMutableArray以便使用UIView方法drawRect绘制。

有了这个解决scheme,我有一个问题时, points组保持重要的点数。 我怎么解决这个问题? 如何在不清除UIView情况下调用drawRect方法,并只添加最后一行(已绘制的行和points组的最后一个点之间)?

 // Start new array - (void) touchesBegan:(NSSet *) touches withEvent:(UIEvent *) event { self.points = [NSMutableArray array]; CGPoint pt = [[touches anyObject] locationInView:self]; [self.points addObject:[NSValue valueWithCGPoint:pt]]; } // Add each point to array - (void) touchesMoved:(NSSet *) touches withEvent:(UIEvent *) event { CGPoint pt = [[touches anyObject] locationInView:self]; [self.points addObject:[NSValue valueWithCGPoint:pt]]; [self setNeedsDisplay]; } // Draw all points - (void) drawRect: (CGRect) rect { if (!self.points) return; if (self.points.count < 2) return; CGContextRef context = UIGraphicsGetCurrentContext(); [current set]; CGContextSetLineWidth(context, 4.0f); for (int i = 0; i < (self.points.count - 1); i++) { CGPoint pt1 = POINT(i); CGPoint pt2 = POINT(i+1); CGContextMoveToPoint(context, pt1.x, pt1.y); CGContextAddLineToPoint(context, pt2.x, pt2.y); CGContextStrokePath(context); } } 

谢谢阅读。

现在它工作正确。 SkylarEC 在这里有一个很好的教程,他解释了如何解决这个问题。 谢谢阅读。