3

I use this is Range slider in my project. How use it.

I want to detect, when user finished moving Range slider. I tried to use function SliderAction(sender: RangeSlider), but I get each moving points in the slider. I think I need to use this function: func endTrackingWithTouch(touch: UITouch?, withEvent event: UIEvent?), but it is doesn't work. How can I make it?

Dim
  • 532
  • 1
  • 6
  • 23

5 Answers5

5

To detect when user finished moving the range slider you can add a controlevent to your slider , you can add it programatically :

mySlider.addTarget(self, action: "sliderDidEndSliding:", forControlEvents: .UIControlEventTouchUpInside)

then you have to do your logic the recieving methode .

    func sliderDidEndSliding(sender: UISlider) {
}
MedAmine.Rihane
  • 1,193
  • 10
  • 17
1

For swift 3 I used this:

mySlider.addTarget(self, action: #selector(self.sliderDidEndSliding), for: .touchUpInside) 

func sliderDidEndSliding() {
  // process stuff 
}

reading values is done with:

@IBAction func mySlider(_ sender: Any) {

}
Wil
  • 351
  • 3
  • 9
0

based on this example viewcontroller, you should check the value sender.selectedMax value changed should be equal to the one you set in storyboard for that slider view

enter image description here

xmhafiz
  • 3,482
  • 1
  • 18
  • 26
0

You need to override endTrackingWithTouch. It'll get called when tracking ends by the underlying machinery, giving you a chance to respond.

Be sure and call the super of this during your version of endTrackingWithTouch so the the parents classes can do their bit.

Hack Saw
  • 2,741
  • 1
  • 18
  • 33
0

Swift 4

slider.addTarget(self, action: #selector(sliderDidEndSliding), for: .touchUpInside)

and add

@objc func sliderDidEndSliding(sender: UISlider) {
}
T3iX
  • 1
  • 1