Search code examples
iosswiftuiimageviewuislideruitapgesturerecognizer

One of two practically identical UITapGestureRecognizers acting much slower than the other


I have 2 almost identical tap gestures like so:

let minusGesture = UITapGestureRecognizer(target: self, action: Selector("minusSlider:"))
minusGesture.numberOfTapsRequired = 1
downArrowImageView.addGestureRecognizer(minusGesture)

let plusGesture = UITapGestureRecognizer(target: self, action: Selector("plusSlider:"))
plusGesture.numberOfTapsRequired = 1
upArrowImageView.addGestureRecognizer(plusGesture)

They trigger practically identical actions like so:

func minusSlider(sender: UITapGestureRecognizer) {
    if mySlider.value > mySlider.minimumValue {
        mySlider.value -= 1
    }
}

func plusSlider(sender: UITapGestureRecognizer) {
    if mySlider.value < mySlider.maximumValue {
        mySlider.value += 1
    }
}

Here's a screenshot for context. Basically tapping the respective arrow moves the slider value up or down by 1.

enter image description here

When I tap the up arrow, it's very responsive. I can tap rapidly and it works properly. However, when I tap the down arrow, it triggers the action achingly slow. It only works if I tap really slow. If I tap at a quicker pace it's very unresponsive, only working every few taps, and I receive this error the rest of the time:

<_UISystemGestureGateGestureRecognizer: 0x17d3aac0>: Touch: Failed to receive system gesture state notification before next touch

Why is this error occurring on only the down arrow tap gesture and not the up arrow? There is nothing else that separates these two gestures aside from what I posted above and the fact that they are on opposite edges of my view.


Solution

  • Try - requireGestureRecognizerToFail

    https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIGestureRecognizer_Class/#//apple_ref/occ/instm/UIGestureRecognizer/requireGestureRecognizerToFail:

    Or - gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:

    https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UIGestureRecognizerDelegate_Protocol/index.html#//apple_ref/occ/intfm/UIGestureRecognizerDelegate/gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:

    Somehow the minusGesture is getting overriden by other gestures on your view.