I am new to iPhone application development.
I wrote code to draw and erase but, I am unable to do the undo and redo operations.
I used am using CoreGraphics in my application. Please help me to fix the undo redo issue.
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I put together a little sketching app in Flash a few years ago and implemented undo/redo functionality. I don’t know that this is the right way of doing it (probably not), but I can give you a high level view of what I did.
The basic concept is this (like Andy mentioned): Have a stack of recently executed actions. If you can, have your “undo” action truly undo the last action. Put this “undo” action into a different stack, so that you can provide “redo” functionality. When someone clicks “redo”, do the same thing but in reverse — execute the action in the “redo” stack and put that into the other stack. Once someone does something new (i.e., not “redo” or “undo”), get rid of the “redo” stack and start adding to the main stack.
What was interesting for me was that I couldn’t figure out a way to truly “undo” an action (i.e., I didn’t know how to undraw a stroke). What I did instead was I drew all the strokes up to the last action. As you can imagine, that’s not very efficient. I made it more efficient by having stacks of stacks. That way, the latest “undo” action would only have to undo the last stack’s worth of actions, instead of the entire history of all the actions.
Hope this helps!