CALayer渲染问题与对角虚线

时间:2014-07-10 05:25:26

标签: ios core-graphics calayer

我使用下面的代码创建了一个虚线CAShapeLayer。当线路在完全水平的平面上时,线条会正确绘制。但是,只要路径向上或向下移动,该线就会遇到一些问题。以图片为例。

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;

如果有人对绘制这些形状有一些建议,那么听起来很棒。

Correct

Incorrect

0 个答案:

没有答案