0

I'm using SceneKit to render a 3D model on an iPad Pro. My requirement is that I'd like to perform different interactions when using the Apple Pencil.

Is there a way to distinguish between a finger touch and an Apple Pencil touch?

I tried overriding the touchesBegan function and filtering the UITouch in the Set to ignore the ones with type pencil, but that doesn't seem to do anything...

EDIT: I'm more interested in handling these 2 different types of touches (i.e. when the there's a finger touch event, I want to do some action A. If it's pencil, I want to do action B). Which methods do I even override to achieve this segregation?

7ball
  • 2,183
  • 4
  • 26
  • 61
  • Look at the majorRadius of the UITouch object. Use that for filtering. The pencil has a unique value. – Peter Kämpf Apr 17 '19 at 14:10
  • Does this answer your question? [How to differentiate whether a user is tapping the screen with his finger or an apple pencil?](https://stackoverflow.com/questions/37133248/how-to-differentiate-whether-a-user-is-tapping-the-screen-with-his-finger-or-an) – Senseful Feb 11 '20 at 17:21

3 Answers3

0

Easy way of checking is a UITouch object will have additional information that comes from a stylus (Such as Apple Pencil). Check if this information exists on the object and if it does the UITouch object came from a stylus.

For more in-depth information I have linked below an input guide for the Apple Pencil from the developer documentation.

Can you provide code however as the type on UITouch should still be reported correctly?

https://developer.apple.com/documentation/uikit/pencil_interactions/handling_input_from_apple_pencil

SierraMike
  • 1,539
  • 1
  • 11
  • 18
  • Hi, I guess I should have worded my question a little better. Do you know how to perform some handler if the touch is from the pencil and some other different handler if it's finger touch? – 7ball Apr 16 '19 at 17:46
0

The key is the UIGestureRecognizer class. "The base class for concrete gesture recognizers" said apple documentation

It has a property called allowedTouchTypes that can be used to distinguish different type of touches.

This property is an array of touch types that recognizes whether the touch is direct or indirect. For a list of all possible touch types, see UITouch.TouchType enumeration in UITouch. The default value of this property contains all touch types.

The gesture recognizer distinguishes between the touch types by setting the allowedTouchTypes property to UITouch.TouchType.pencil when tracking Apple Pencil touches, and to UITouch.TouchType.direct when tracking touches from a finger.

Also, i've Found this one on the apple documentation. this tutorial provides helper method that can help Distinguish Between Finger and Apple Pencil Touches. =>

CocodyRockStar
  • 230
  • 2
  • 8
0

Apple's documentation says, "A touch object originating from Apple Pencil contains additional information, including the azimuth and altitude of Apple Pencil and the amount of force recorded at its tip." However, checking (touch.altitudeAngle > 0) didn't work for me because some finger touches also have an angle set. I tried (touch.majorRadiusTolerance == 0) and that seemed reliable. Then I realized we can simply check (touch.type == .pencil).

arlomedia
  • 8,534
  • 5
  • 60
  • 108