Search code examples
iosswiftpencilkit

Remove UIEditMenuInteraction from PKCanvasView


I have been working with PencilKit for quite some time now and never had any problems with it. However, since updating to iOS17 my app shows a menu when the PKCanvasView is tapped.

enter image description here

As I implement my own menu I want to remove this, but unfortunately I do not have any idea how to do this.


Solution

  • This is the thing that worked for me

    extension PKCanvasView {
        func disableMenuInteractions() {
            let views = [self] + self.allSubviewsRecursive()
            for view in views {
                for interaction in view.interactions where interaction is UIEditMenuInteraction {
                    view.removeInteraction(interaction)
                }
            }
        }
    }