I am having trouble using a UITapGestureRecognizer in conjunction with a UISlider in swift

Viewed 41

I am using a UISlider with a custom thumb. The user is meant to slide the thumb to a given point and then double tap to input a value. Used to work fine until the latest update, Now, for some reason, the tap no longer works when the user taps on the thumb itself (fine if they tap elsewhere, including the slider body). But, of course, the user will nearly always try and double tap on the thumb. With no success. In fact I see that the slider moves slightly when tapped, regardless of how much care one take to tap correctly.

How can I configure the slider to accept the tap on the thumb itself?

I tried using one gesture recognizer and adding that to both view and slider, then I tried making a gesture recognizer for each. Neither approach worked.

Here is the very simple code I am using:

@IBOutlet weak var videoSlider: UISlider!

// In the viewdidload:
//add tap gesture recognizer to view
        let tap = UITapGestureRecognizer(target: self, action: #selector(doubleTapped))
        tap.numberOfTapsRequired = 2
        view.addGestureRecognizer(tap)

// make the slider thumb arrow
        videoSlider.setThumbImage(UIImage(named: "ARROW"), for: .normal) 

// create a gesture recognizer for the slider
let tapSlider = UITapGestureRecognizer(target: self, action: #selector(doubleTappedSlider))
        tapSlider.numberOfTapsRequired = 2
        videoSlider.addGestureRecognizer(tapSlider)
0 Answers
Related