I am working on a drawing app, I have a UIBezeirPath, with which I draw in touchesMoved, and convert it to CGPath and then draw on to CGlayer,
Here is my code
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
self.currentPath = [[DrawingPath alloc] init];
if(m_eraseButtonClicked)
{
[self.currentPath setPathColor:[UIColor backgroundColor]];
}
else
{
[self.currentPath setPathColor:self.lineColor];
}
CGPathRef cgPath = self.currentPath.path.CGPath;
mutablePath = CGPathCreateMutableCopy(cgPath);
}
- (void)Erase
{
CGContextRef layerContext = CGLayerGetContext(self.DrawingLayer);
CGContextSetBlendMode(layerContext,kCGBlendModeClear);
CGContextSetLineWidth(layerContext, self.eraseWidth);
CGContextBeginPath(layerContext);
CGContextAddPath(layerContext, mutablePath);
CGContextStrokePath(layerContext);
}
- (void)UndoRedoFunction
{
//Undo/Redo
for(int i =0; i<[undoArray count];i++)
{
DrawingPath *drawPath = [undoArray objectAtIndex:i];
CGPathRef path = drawPath.path.CGPath;
mutablePath = CGPathCreateMutableCopy(path);
CGContextBeginPath(layerContext);
CGContextAddPath(layerContext, mutablePath);
CGContextSetLineWidth(layerContext, drawPath.pathWidth.floatValue);
CGContextSetStrokeColorWithColor(layerContext, drawPath.pathColor.CGColor);
CGContextSetFillColorWithColor(layerContext, drawPath.pathColor.CGColor);
CGContextSetBlendMode(layerContext,kCGBlendModeNormal);
CGContextStrokePath(layerContext);
CGPathRelease(mutablePath);
}
}
Erase works fine, because I use blendMode Clear, but when undo/Redo, as you can see, I get the pathColor from path and stroke it with blenModeNormal, I see a white line,
Below is the image,after I write->erase->undo->redo