Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swipe gesture interrupts UISlider control in iOS 13, but not previous iOS versions

Note: This is the iOS 13 beta, but also could apply to the official release tomorrow.

Update 2: I replaced it with a larger thumb image, and I'm still having a problem.

Update: It looks like it still controls continuously if I'm super precise about touching the thumb on the slider. But why is this changed, and how can I make it control like before?

I have a swipe gesture recognizer added to my view:

    let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(self.respondToSwipeGesture))
    swipeRight.direction = UISwipeGestureRecognizer.Direction.right
    self.view.addGestureRecognizer(swipeRight)

Later on, I add a UISlider to the same view:

        let slider = UISlider()
        let sliderLength:CGFloat = 175
        slider.frame = CGRect(x:0,
                              y:CGFloat(customHeight) - 35,
                              width:sliderLength,
                              height:35)


        slider.minimumValue = -1.2 
        slider.maximumValue = 0.6
        slider.setValue(Float(snowSliderValAdder), animated: false)

        slider.addTarget(self, action: #selector(self.updateSnowSliderValue(_:)), for: .valueChanged)

        view.addSubview(slider)

What used to work fine, now behaves poorly in iOS 13. I can move the thumb on the slider if I move it very slowly, but if I do any kind of a swiping motion, the thumb on the slider stops moving and the gesture is triggered. How can I stop this from happening?

like image 720
Chewie The Chorkie Avatar asked Nov 28 '22 05:11

Chewie The Chorkie


2 Answers

What I did was use a gestureRecognizer function to stop any gestures if a touch was detected on my UISliders. Make sure to add UIGestureRecognizerDelegate and set the UISwipeGestureRecognizer's delegate to self.

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {

   if touch.view == self.view.viewWithTag(viewTags.MySlider.rawValue) {
        return false
   }
   else if touch.view == self.view.viewWithTag(viewTags.AnotherSlider.rawValue) {
        return false
   }

   return true
}
like image 23
Chewie The Chorkie Avatar answered Dec 10 '22 00:12

Chewie The Chorkie


I had the same issue and managed to resolve it by doing the following:

Add a panGesture ,that does nothing, to your sliders and set their cancelsTouchesInView propery to false.

let panGesture = UIPanGestureRecognizer(target: nil, action:nil)
                    panGesture.cancelsTouchesInView = false
                    slider.addGestureRecognizer(panGesture)

Now your sliders should slide like a knife cutting a butter with no swipe interruption.

like image 99
Ahmad AJR Avatar answered Dec 10 '22 00:12

Ahmad AJR