使用UIGraphics绘图的NSUndoManager实现

时间:2019-06-19 13:23:26

标签: ios objective-c nsundomanager

我正在使用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];
    }
}

0 个答案:

没有答案