Search code examples
iosuikitios13ios13.4

Secondary mouse click on iOS13.4


Just playing with the new mouse/trackpad support in iOS13.4 and trying to detect both primary and secondary mouse button clicks.

I can detect them (primary OR secondary clicks) by setting the buttonMaskRequired on a UITapGestureRecognizer to EITHER UIEventButtonMaskPrimary or UIEventButtonMaskSecondary

BUT if I attempt to recognise both (buttonMaskRequired = UIEventButtonMaskPrimary | UIEventButtonMaskSecondary) then the gesture recogniser doesn't fire (for mouse clicks.)

Anyone know if this is an 'oversight' or I'm doing something wrong?


Solution

  • I have since made progress - but it feels real hacky.

    Create 2 tap gesture recognisers - one with primary mask set, and the other with secondary mask set. I then kill the secondary gesture in the gestureRecognizerShouldBegin: delegate call if the UITouch type is UITouchTypeDirect so as to stop use getting 2 tap events with a finger.