I am adding a simple drawing capability to an app and I want the user to be able to draw dashed lines. I have the drawing routine working just fine, adding a CAShapeLayer and setting the path.
However, when I try to draw dashed lines the dashes are apparent only when the user draws very FAST. If I draw slowly the line is solid as the dashes are bunched together.
Step 1. Start a new drawing layer. Some code obviously left out.
// CAShapeLayer
// Dashed pattern is arbitrary - I've tried a variety of values
[self.currentDrawLayer setLineDashPattern:[NSArray arrayWithObjects:
[NSNumber numberWithInt:6],
[NSNumber numberWithInt:12],
nil]];
currentPenPath = [UIBezierPath bezierPath];
[currentPenPath moveToPoint:currentPoint];
Step 2. Add points as the user draws and update the layer.
[currentPenPath addLineToPoint:currentPoint];
[currentPenPath moveToPoint:currentPoint];
[[self currentDrawLayer] setPath:currentPenPath.CGPath];
I want the user to be able to draw as slow or fast as they want and have consistent dashes while drawing. Do I need to smooth out all of the points or something first?
Is there a simple way to draw dashes as the user draws?
Any guidance is appreciated.