Post

Replies

Boosts

Views

Activity

Reply to Overriding / modifying the default PencilKit edit menu?
I updated to iPadOS 16.1 20B79 yesterday. This menu no longer shows up upon single tap / long press. I couldn't find this change mentioned in the release note though. Has anyone observed the same? More observations: right clicks on a physical input device (mouse / trackpad) still bring up a context menu with these two buttons. The Select All is still unacceptably slow if you have a larger canvas / large amount of strokes (this was the reason why I wanted to get rid of this menu). I wonder how the upcoming Freeform app is gonna tackle this; and if it does, whether the API will be updated accordingly.
Oct ’22
Reply to PKCanvasView no longer shows edit (paste) menu on long press (iOS 16.1)
@mbuchetics you're welcome! To my knowledge, in order to paste at the right location, you have to implement your own paste function, by subclassing the PKCanvasView and overriding paste(:_). In this override you have to modify the underlying PKDrawing yourself, roughly like so: /// Edit menu location, set by whatever method you use to trigger the edit menu. var editMenuLocation: CGPoint = .zero /// Pasting at `editMenuLocation`. override func paste(_ sender: Any?) { guard let data = UIPasteboard.general.data(forPasteboardType: "com.apple.drawing"),         let drawing = try? PKDrawing(data: data)     else { return }     let center = CGPoint(x: drawing.bounds.midX, y: drawing.bounds.midY)     let target = editMenuLocation / zoomScale // I have some CGPoint extensions dealing with arithmetic     let offset = target - center     let withOffset = drawing.transformed(using: .init(translationX: offset.x, y: offset.y))     let strokes = withOffset.strokes     self.drawing.strokes.append(contentsOf: strokes) } The problem is that by modifying the PKDrawing directly you confuses the default UndoManager, and therefore may have to implement your own undo stack. I'm still developing my first (and likely only) PencilKit app and haven't really got to the undo/redo stage, so my knowledge here is limited.
Oct ’22
Reply to PKCanvasView no longer shows edit (paste) menu on long press (iOS 16.1)
@joaqo thanks for the kind words, it's nice to meet a fellow sufferer :) I ended up implementing my own undo stack. I needed it anyway since I had to support pasting images etc. I asked an engineer in a WWDC lab this year, and he said (basically, my interpretation, not his exact words) that this was the intended way of doing this. I haven't been working on this for quite some time, and I remember I had some issues with the undo stack using this method in some rare cases. But now when I try to find where it breaks, I can't really find any (should have documented them..). How did you solve this in the end? If you see problems about the undo stack, could you share with me so I can check again in my code?
Jun ’23