4

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?

Chewie The Chorkie
  • 4,896
  • 9
  • 46
  • 90

5 Answers5

23

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.

Ahmad AJR
  • 238
  • 1
  • 4
  • 8
    Where did you graduate from? Hogwarts? – CopperCash Sep 24 '19 at 12:47
  • 1
    This doesn't work (May 2020) and feels very "hack-y". What's the right way of doing this? – DS. May 28 '20 at 15:49
  • This SO thread has the correct answer that shows the proper way of doing it - https://stackoverflow.com/questions/4765661/gesture-problem-uiswipegesturerecognizer-uislider/4766026#4766026 – DS. May 28 '20 at 16:39
1

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
}
Chewie The Chorkie
  • 4,896
  • 9
  • 46
  • 90
1

SWIFT 5

The Problem can be solve using delegate method of gesturerecognizer as below

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
    if touch.view?.isKind(of: UISlider.self) ?? false {
        return false
    } else {
        return true
    }
}
kalpa
  • 884
  • 1
  • 15
  • 22
0

I tried to find something during the last hour. It looks like the swipe gesture recognizer as interferance with UISlider.

The problem appears only if you are using right/left direction. Perhaps you should wait before update your app or change your UI to use the up/down swipe gesture.

At this time the slider works normally if you wait a bit before you move your finger. Hoping Apple will fix it quickly.

0

Overriding the method for a custom view your have created can also solve the problem.

override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
    return gestureRecognizer.view is Your_Custom_View
}
aashish tamsya
  • 4,903
  • 3
  • 23
  • 34