0
绘图
我在绘图应用程序的工作,我有一个UIBezeirPath,与我在touchesMoved画,并将其转换为CGPath,然后画上CGlayer,橡皮擦iOS中
这里是我的代码
-(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);
}
}
擦除工作得很好,因为我用的BlendMode清除,但当撤销/重做,你可以看到,我从路径和中风它与blenModeNormal的pathColor,我看到的白线,
下面是图像,我写 - >擦除 - >撤消 - >重做
我已更新它,请现在检查 – Ranjit