So, I know the title of my question may not be the most descriptive so I'll run through it here:
Basically what I have is view with an image (using a layer's contents property) and under that layer I have a Drawing layer which is a CAShapeLayer. In my view where both layers live I also have a CALayerDelegate which, for now, just draws a point using CGPaths with a given color in response to a tap gesture (tap gesture selector calls setNeedsDisplay on the CAShapeLayer). The problem I have is that if I change a color, then tap the view all previous points automatically become the newly selected color...not good...I need each subpath (i.e. point) to maintain its original color...Maybe some code will shed a little more light on the topic:
The delegate (Note: drawingView.drawingPath is reused):
- (void)drawLayer:(CAShapeLayer *)theLayer
inContext:(CGContextRef)theContext {
if (CGPointEqualToPoint(drawingView.startPoint, drawingView.endPoint)) {
CGPathMoveToPoint(drawingView.drawingPath, NULL, drawingView.startPoint.x, drawingView.startPoint.y);
CGPathAddEllipseInRect(drawingView.drawingPath, NULL, CGRectMake(drawingView.startPoint.x, drawingView.startPoint.y, drawingView.drawRadius, drawingView.drawRadius));
CGContextSetFillColorWithColor(theContext, drawingView.currentColor.CGColor);
CGContextBeginPath(theContext);
CGContextAddPath(theContext, drawingView.drawingPath);
CGContextFillPath(theContext);
}
}
And my tap gesture recognizer:
- (void)viewTapped:(UITapGestureRecognizer *)recognizer {
CGPoint touchPoint = [recognizer locationInView:recognizer.view];
startPoint = endPoint = touchPoint;
[drawingLayer setNeedsDisplay];
}
I would be ecstatic if someone can show me what I'm doing wrong here! :(