I've written a program for drawing in iOS in touchesMoved() method.
CGContextAddPath(UIGraphicsGetCurrentContext(), path);
CGPathMoveToPoint(path, NULL, lastPoint.x, lastPoint.y);
CGPathAddLineToPoint(path, NULL, lastPoint.x, lastPoint.y);
CGContextDrawPath(UIGraphicsGetCurrentContext(), kCGPathStroke);
How can i clear the path drawn and restore the original view?
Perhaps you can put an invisible view above your view of drawing and add the path traced by the user only when u are sure that the user will not undo. If the user wants the undo action, don't add the path to the context. Thats my logic. I am not sure how it can be implemted. Hope this helps.
来源:https://stackoverflow.com/questions/9094772/clearing-cgpath-path-after-drawing-is-done