I have a custom UIGestureRecognizer for two-finger gestures that works great, except that it is very picky about how the fingers should touch an iOS device at the same time touchesBeganfor a two-touch call. touchesBeganoften called with just one touch, although I'm trying to use two fingers.
Is there a way to recognize how many Touches are more forgiving regarding how you should place your fingers on the touch screen at the same time?
I noticed that two finger keys are recognized even when you place one finger first and then the other much later, still holding the first finger down.
Here is the code for my function touchesBegan:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent) {
if touches.count != 2 {
state = .failed
return
}
// Capture the first touch and store some information about it.
if trackedTouch == nil {
trackedTouch = touches.min { $0.location(in: self.view?.window).x < $1.location(in: self.view?.window).x }
strokePhase = .topSwipeStarted
topSwipeStartPoint = (trackedTouch?.location(in: view?.window))!
// Ignore the other touch that had a larger x-value
for touch in touches {
if touch != trackedTouch {
ignore(touch, for: event)
}
}
}
}