The App supports iPad Pro and it has to work with the Apple Pencil. What I would like to do is to differentiate whether the user is using the Apple Pencil or his finger.
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.
The UITouch
class in iOS 9.1 has a touch property which returns the type:
typedef enum {
UITouchTypeDirect,
UITouchTypeIndirect,
UITouchTypeStylus // THIS ONE
} UITouchType;