我正在使用UIGraphics绘制图像。我正在实现NSUndoManager,并且想在绘制时以相反的顺序撤消,但是撤消正在清除所有图形。
在我的draw方法中,我正在此行注册
[[undoObject prepareWithInvocationTarget:self] performUndoWithObject:context withLastpoint:to andFirstPoint:from];
这是在撤消时触发的方法
-(void)performUndoWithObject:(CGContextRef )context withLastpoint:(CGPoint)previousLastPoint andFirstPoint:(CGPoint)previousFirstPoint
{
CGContextSetBlendMode(context, kCGBlendModeClear);
CGContextMoveToPoint(context, previousFirstPoint.x, previousFirstPoint.y);
CGContextAddLineToPoint(context, previousLastPoint.x, previousLastPoint.y);
CGContextStrokePath(context);
_drawingView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
-(void)undoButtonClicked
{
if([undoObject canUndo])
{
[undoObject undo];
}
}