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