Thorsten Dittmar
Thorsten Dittmar

Reputation: 56727

Clear undo buffer for PKCanvasView

I'm experimenting with Apple's PencilKit. Showing the PKToolPicker works well and I can draw into my canvas. However, I wondered whether and if so, how it is possible to clear the undo buffer.

Background: I'm allowing the user to flip through his drawings, but the undo buttons are still available on the iPad even if I assign a new drawing to the PKCanvasView. I would like to clear the undo buffer before I show one of the previous drawings.

I've tried to clear the parent view controller's undo buffer and the PKCanvasView's undo buffer by calling

self.undoManager?.removeAllActions()
self.canvasView.undoManager?.removeAllActions()

to no avail.

Optionally, it would also be ok for me to just hide the undo/redo buttons from the PKToolPicker on the iPad. Is this possible?

Upvotes: 3

Views: 920

Answers (1)

gdub
gdub

Reputation: 897

undoManager?.removeAllActions() does work. The key is to wait for viewDidAppear as undoManager was nil until then.

Also the canvas' undoManager and view controller's undoManager both point to the same instance by default.

Upvotes: 0

Related Questions