I am working on an app and i have to draw a smooth line so I followed this link to smooth the line iPhone smooth sketch drawing algorithm and I followed the answer of kyoji. But now I don’t know how to implement Undo Redo functionality.
Please help
Use the NSUndoManager. However, if you are painting lines on the canvas, you will also need to keep their representation around as well (so you can pop them off).
So, whether you collect them as a UIBezierPath, or use shape layers, or your own “array of points” you undo in the same manner.
So, while drawing the line, keep a record of the points you used in your drawing. When the drawing is done (e.g., touchesEnded), you want to “push” your drawing, and tell the undo manager how to undo it. Simply, it would be something like this almost-code…
If you are using one canvas, you may have to redraw the entire thing, especially when popping a drawing off. If you are using views or layers, you may not…
Look at the docs for NSUndoManager… it’s available on iOS, and has good examples. It “remembers” if you you undo-ing or redo-ing, and will do the right thing, so the above could be implemented as one function (but it’s easier to understand at first with one function going each direction).