How to differentiate whether a user is tapping the screen with his finger or an apple pencil?
To check if a UITouch
is using the stylus touch type in Objective-C:
if (touch.type == UITouchTypeStylus) {
// Do stuff
}
If you're not handling touches directly, but using a gesture recognizer, then it is a little more complicated.
You could try adding a second long press gesture recogniser and setting the allowedTouchTypes
property on each one to recognise stylus or direct touches:
longPressGestureFinger.allowedTouchTypes = @[@(UITouchTypeDirect)];
longPressGesturePencil.allowedTouchTypes = @[@(UITouchTypeStylus)];
If that doesn't work, you would have to add a delegate to the long press gesture, and in the gestureRecognizer: shouldReceiveTouch:
method, check and store the type of touch and use this when the gesture action fires.