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 overridetouchesBegan,touchesMovedand so on and get access to theUITouchobject that will includeUITouch.TouchType.See Apple's Sample Code here, specifically the
StrokeGestureRecognizerclass.