I am wondering if there is a way to handle Apple Pencil events in SwiftUI? For example if you like to handle direct touches, and Apple Pencil differently, say direct touch to scroll, but Apple Pencil to draw lines.
There is a similar type of question like this.
How to Handle screen touch events with SwiftUI?
But DragGesture
, for example, there seems to be no accessor to UITouch.TouchType
like attributes to distinguish direct
, indirect
or pencil
.
If there is no way, or giving me some hybrid techniques with UIView, then oh well...
Thanks,
I think the best way to do this is to create a custom UIGestureRecognizer
. This way you can override touchesBegan
, touchesMoved
and so on and get access to the UITouch
object that will include UITouch.TouchType
.
See Apple's Sample Code here, specifically the StrokeGestureRecognizer
class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With