I have a UISlider
and I am trying to make the position go when the user taps to a certain time, instead of moving the thumb.
I tried to work it through this topic and this answer and I came to this approach. This is what I tried:
var slider: UISlider! // and maxValue, etc added in viewDidLoad
func sliderTapped(gestureRecognizer: UIGestureRecognizer) {
var pointTapped: CGPoint = gestureRecognizer.locationInView(self.view)
var positionOfSlider: CGPoint = slider.frame.origin
var widthOfSlider: CGFloat = slider.frame.size.width
var newValue = ((pointTapped.x - positionOfSlider.x) * CGFloat(slider.maximumValue) / widthOfSlider)
slider.setValue(Float(newValue), animated: true)
}
But, it is not letting me anywhere on slider and get the tapped value. It only lets me hold the thumb and slide it, but not tapping.