UIViewController not handling Apple Pencil Double Tap events

I am unable to get a UIViewController to receive the UIPencilInteractionDelegate “pencilInteractionDidTap” method in response to double taps from an Apple Pencil. I am testing on iPad Pro 11 and 12.9 models, both running iOS 13.3.1


I have implemented the following:


extension UIViewController: UIPencilInteractionDelegate {

public func pencilInteractionDidTap(_ interaction: UIPencilInteraction) {

print("Handle pencil double-tap")

}

}


In my UIViewController:


override func viewDidAppear(_ animated: Bool) {

super.viewDidAppear(animated)

let pencilInteraction = UIPencilInteraction()

pencilInteraction.delegate = self

view.addInteraction(pencilInteraction)

}



Note: If I create a new Single View iOS app and add this code, everything works as expected.


However the above code does not work with the custom UIViewController in my app. My UIViewController’s view hosts a UIScrollView as well as overlaying Container Views and handles touch events in both the View Controller and ScrollView classes.


I have also tried adding the UIPencilInteraction object to other UIViewControllers in my app and the “pencilInteractionDidTap” method is not called in any of them.


Do I need to change something in the Responder chain to get the UIViewController to handle “pencilInteractionDidTap” method calls?

Replies

Rick, have you found a solution to this?
In my case, granted on the beta version of iOS, I noticed that code will only react the second time the same VC was initialized which is strange, too.
I have found a possible cause and a workaround to fix this problem.

I found out that my pencilInteractionDidTap is not called if the view-controller that contains this interaction is presented via my own custom modalPresentationStyle. (Using my own Transitioning Controller)
If I change the modalPresentationStyle to a standard (.fullscreen) when presenting the above controller, the interaction works fine.

The problem could either be in my own transitioning code, or iOS. I have not investigated that part.

Also, when I was experimenting by creating a fresh app from templates, I found out that I had to pair my Apple Pencil at-least once even if it was already paired. Not sure if the pencil needs to do re-initialization in order to send the interactions to the new app.