我正在开发一个绘图应用程序,我有一个UIBezierPath,我用它在touchesMoved中绘制,并将其转换为CGPath,然后在tCGplayer上绘制,
这是我的代码
-(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 Clear,但是当撤消/重做时,如您所见,我从路径中获取 pathColor 并使用blenModeNormal 对其进行描边,我看到一条白线,
下面是我写入->擦除->撤消->重做后的图像
您正确粘贴了代码吗?如图所示,-touchesMoved:withEvent 方法在第 14 行左右关闭,就在//Erase
陈述。这意味着您的 CGContextRef 现在是一个类变量,并且您的 for 循环永远不会被任何人执行,而且我认为它不会编译,因此我想知道您是否省略了一些代码。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)