我正在创建一个这样的 UIBezierPath
:
UIBezierPath *path = [UIBezierPath bezierPath];
[path addLineToPoint:CGPointMake(200.0, 40.0)];
[path addLineToPoint:CGPointMake(160, 140)];
[path addLineToPoint:CGPointMake(40.0, 140)];
[path addLineToPoint:CGPointMake(0.0, 40.0)];
[path closePath];
问题是,当我尝试绘制
UIBezierPath
时,它没有出现,并且出现错误:<Error>: void CGPathCloseSubpath(CGMutablePathRef): no current point.
我的绘图代码非常基本:
UIGraphicsBeginImageContext(self.view.bounds.size);
[[UIColor whiteColor] set];
[myPath stroke];
UIGraphicsEndImageContext();
我究竟做错了什么?
最佳答案
错误信息很清楚。创建 UIBezierPath
时缺少一行代码:
[path moveToPoint:CGPointMake(0, 0)];
我添加了它,一切都像魅力一样。
UIBezierPath *path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(0, 0)];
[path addLineToPoint:CGPointMake(160, 140)];
[path addLineToPoint:CGPointMake(40.0, 140)];
[path addLineToPoint:CGPointMake(0.0, 40.0)];
[path closePath]
有趣的是,错误发生在我试图画线时而不是之前 - 当我创建它时。