我有一个习惯UIView
。当手指触摸移动时,我会保持线条和点。然后我CGPath
用这个方法指出:</p>
- (void)makeCGPath
{
CGMutablePathRef path = CGPathCreateMutable();
if (lines&& lines.count>0)
{
for (int i = 0; i < lines.count; i++)
{
CGMutablePathRef linePath = CGPathCreateMutable();
NSArray *tempArray = [lines objectAtIndex:i];
CGPoint p = [[tempArray objectAtIndex:0]CGPointValue];
CGPathMoveToPoint(linePath, NULL, p.x, p.y);
for (int j = 1; j < tempArray.count; j++)
{
p = [[tempArray objectAtIndex:j]CGPointValue];
CGPathAddLineToPoint(linePath, NULL, p.x, p.y);
}
CGPathAddPath(path, NULL, linePath);
CGPathRelease(linePath);
}
}
if (points&& points.count > 0)
{
CGMutablePathRef pointPath = CGPathCreateMutable();
CGPoint p = [[points objectAtIndex:0]CGPointValue];
CGPathMoveToPoint(pointPath, NULL, p.x, p.y);
for (int i = 1; i < points.count;i++ )
{
p = [[points objectAtIndex:i]CGPointValue];
CGPathAddLineToPoint(pointPath, NULL, p.x, p.y);
}
CGPathAddPath(path, NULL, pointPath);
CGPathRelease(pointPath);
}
drawPath = CGPathCreateCopy(path);
[self setNeedsDisplay];
[lines removeAllObjects];
[points removeAllObjects];
}
我的 drawRect 看起来像这样。
- (void)drawRect:(CGRect)rect
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(ctx, 3);
[[UIColor blackColor]set];
CGContextAddPath(ctx, drawPath);
CGContextStrokePath(ctx);
}
看起来很奇怪,它只显示屏幕上的最后一行。它出什么问题了?
如何将所有这些路径保留在屏幕上?