CALayer rendering issues with diagonal dashed line

别来无恙 提交于 2020-01-05 08:31:33

问题


I've created a dashed CAShapeLayer using the code below. The line draws correctly when its path is on a perfectly horizontal plane. However as soon as the path moves up or down, the line suffers from some issues. See the images as an example.

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;

If anyone has some advice about drawing these kinds of shapes it'd be great to hear.

来源:https://stackoverflow.com/questions/24669029/calayer-rendering-issues-with-diagonal-dashed-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!