0

My ViewController has multiple UIViews in it. User is able to resize/move the UIViews by dragging them. I have implemented this by subclassing UIView and using touch delegates.

No I want to implement NSUndoManager to undo the last operation which occurred on any UIView. How to do that?

I'm pretty new to NSUndoManager. My problem is same is this, but I don;t understand the answer to that question.

Please help. Thanks.

Community
  • 1
  • 1
Hyder
  • 1,163
  • 2
  • 13
  • 37

1 Answers1

1

You don't need multiple undo managers. The undoManager property of your view controller will do fine. Basically, the idea is: whenever a user resizes/moves one of your views, you calculate the corresponding transformation/move that would revert this action and add this information to the undo manager. Then, when a user performs an undo action, the rotation/resize is reverted.

Have a look at this question for an example: NSUndoManager to undo UIImage rotation using rotation gesture

Community
  • 1
  • 1
Tobias
  • 31
  • 2
  • Having a central undo manager has different functionality than a separate one for each view. Consider, for example, a drawing app. The app uses multiple layers, each of which can be drawn on separately. The layers have curves with various thicknesses, opacity, etc. By having a separate undo manager for each layer, the user can perform undo operations specific to the layer they are interested in. With a central undo manager, if they do work on one layer, then work on a second layer, then they can't undo the work on the first layer without undoing the second one first. – Victor Engel Jul 11 '23 at 21:18