我正在尝试使用 Quartz 2d 绘制一条动画生长线,方法是随着时间的推移逐渐向现有线添加点。我开始绘制一条新线,在 UIView 的 drawRect 方法中,通过获取 CGContextRef,设置其绘制属性,并将第一个点移动到 (0,0)。
CGContextRef context= UIGraphicsGetCurrentContext();
CGContextSetStrokeColorWithColor(context,[UIColor blueColor].CGColor);
CGContextSetLineWidth(context, 2);
CGContextMoveToPoint(context,0,0);
后来,在我的下一个 drawRect 调用中,我尝试再次扩展该行,获取 CGContextRef,并为其添加一个新点。
GContextRef context= UIGraphicsGetCurrentContext();
CGContextAddLineToPoint(context,x,y);
但似乎当前的 CGContextRef 没有任何我上次调用 drawRect 的 CGContextMoveToPoint 命令的记录,因此没有任何我已经开始画线的参考。
我在这里做错了吗?有没有办法引用已经绘制的线?