Objective c CAShapeLayer一直在关闭路径,我希望路径打开

Objective c CAShapeLayer一直在关闭路径,我希望路径打开,objective-c,core-animation,Objective C,Core Animation,我正在使用CA从一组点绘制线段。出于某种原因,虽然我没有关闭NSBezierPath,但CAShapeLayer会生成一个闭合的形状。以下是我的代码。还有其他人有这个问题吗 // mappedPoints is an array of CGPoints NSBezierPath *path = [NSBezierPath bezierPath]; [path appendBezierPathWithPoints:mappedPoints count:numPoints]; CAShapeLa

我正在使用CA从一组点绘制线段。出于某种原因,虽然我没有关闭NSBezierPath,但CAShapeLayer会生成一个闭合的形状。以下是我的代码。还有其他人有这个问题吗

// mappedPoints is an array of CGPoints

NSBezierPath *path = [NSBezierPath bezierPath];

[path appendBezierPathWithPoints:mappedPoints count:numPoints];
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
shapeLayer.path = [path CGPath];
shapeLayer.strokeColor = [color CGColor];
shapeLayer.lineWidth = lineWidth;
shapeLayer.fillColor = nil;

[self.layer addSublayer:shapeLayer];

我允许自己在这里猜测,
[path CGPath]
调用正在为您关闭该路径,因为这正是发生在我身上的事情

为了提供更多的上下文,苹果的示例代码创建了一个类似于上面的
CGPath
NSBezierPath
分类方法,其中包含以下内容:

// Be sure the path is closed or Quartz may not do valid hit detection.
if (!didClosePath)
    CGPathCloseSubpath(path);
背后的原因(来自同一来源):

Quartz要求关闭路径,以便在计算机上进行命中检测 路径的填充区域


如果您对填充区域命中检测不感兴趣,那么跳过路径关闭部分是安全的,您将获得预期的行为。

您的代码中是否有
NSBezierPath
上的
CGPath
属性?我不记得
NSBezierPath
有这样的属性,我在文档中找不到它。