1

I have a horizontal CollectionViewCell with a UISlider inside of it. When I try to drag the slider the cell swipes.

How can I prevent the cell from swiping when I drag the slider? I don't want to lose the ability to swipe the cell itself meaning when I swipe the cell it should move to the next cell which the slider has nothing to do with.

class MyCell: UICollectionViewCell {

    lazy var slider: UISlider = {
        let slider = UISlider()
        slider.translatesAutoresizingMaskIntoConstraints = false
        // ...
        return slider
    }()


    // slider is pinned towards the bottom of the cell
}
Lance Samaria
  • 17,576
  • 18
  • 108
  • 256
  • try changing continuos property of slider to no and check once by default this value is set to true – Shakti Jul 15 '20 at 07:26

1 Answers1

1

Got the answer from here which got the answer from here:

override init(frame: CGRect) {
    super.init(frame: frame)

    let panGesture = UIPanGestureRecognizer(target: nil, action:nil)
    panGesture.cancelsTouchesInView = false
    slider.addGestureRecognizer(panGesture)
}
Lance Samaria
  • 17,576
  • 18
  • 108
  • 256