1

The Question

When the user taps on a view which of these two functions is called first? touchesBegan(_:with:) or point(inside:with:).

The Context

I want to subclass a PKCanvasView (which inherits from UIScrollView) to allow interaction through the view (i.e. allow interaction to the view below and disable interaction to the PKCanvasView) when the point of the touch is outside of the UIBezierPath of a stroke on the canvas.

This is easy enough by overriding point(inside:with:). My issue lies in the fact that I only want to allow interaction to the view below if the touch event UITouch.TouchType is not an apple pencil : .pencil. (so that the user can draw with the apple pencil and interact with the view below using their finger)

The only way I think can get this information is by also overriding touchesBegan(_:with:). Here I can access the event and its touch type. I would then somehow pass this to be read inside of point(inside:with:).

However, that all relies on extracting the UITouch.TouchType information before I check if the touch point is overlapping with any PKStroke paths.

So: Is touchesBegan(_:with:) called before point(inside:with:)?

santi.gs
  • 514
  • 3
  • 15
  • 1
    I would think your view's custom `point(inside:with:)` would have to be called first, since that would determine whether or not the gesture recognizer needs to handle the touch. Test it! Create a simple subclass of UITapGestureRecognizer that simply forwards methods like `touchesBegan(_:with:)` to super, but logs it. Same with your custom UIView's `point(inside:with:)`. Then look at the console and see which is called first. – Duncan C May 10 '21 at 18:01
  • Having a similar issue, if you don't mind me asking, how did you resolve this? – Hamster Jan 08 '23 at 05:51

0 Answers0