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

拥有回忆 提交于 2020-08-07 06:32:47

问题


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?


回答1:


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.




回答2:


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.




回答3:


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
}


来源:https://stackoverflow.com/questions/58001780/swipe-gesture-interrupts-uislider-control-in-ios-13-but-not-previous-ios-versio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!