问题
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