CALayer使用对angular虚线渲染问题

我使用下面的代码创build了一个虚线的CAShapeLayer 。 当它的path在完全水平的平面上时,线条正确绘制。 然而,只要path上下移动,线路就会遇到一些问题。 以图像为例。

 CGMutablePathRef linePath = CGPathCreateMutable(); CGPathMoveToPoint(linePath, NULL, startShapeLayer.centerX, startShapeLayer.centerY); CGPathAddLineToPoint(linePath, NULL, endShapeCenter.x, endShapeCenter.y); CGPathCloseSubpath(linePath); CAShapeLayer *lineLayer = [CAShapeLayer layer]; lineLayer.path = linePath; lineLayer.fillColor = [UIColor clearColor].CGColor; lineLayer.strokeColor = [UIColor whiteColor].CGColor; lineLayer.lineCap = kCALineCapRound; lineLayer.lineDashPattern = @[@5, @5]; lineLayer.lineDashPhase = 5.0; lineLayer.lineWidth = 1.0; 

如果任何人有关于绘制这些形状的build议,这将是非常好的听到。

正确

不正确