How to do an action when Eureka Slider is released?

155 Views Asked by At

I have a SliderRow and I would like to take an action but only if the slider is released.

The .onChange does the action every time the user slides a bit (of course). The .onCellHighlightChanged does not work for the SliderRow.

An option for .onSliderReleased would be great ;)

DoI have another options in meanwhile?

<<< SliderRow("Barrel") { row in
                    row.title = "Barrel"
                    row.value = Float(UserDefaultsManager.Barrel())
                    row.steps = 19
                    row.displayValueFor = { row in
                       return "\(Int(row ?? 0)) bbl"
                    }

                }.cellSetup { cell, row in
                    cell.imageView?.image = UIImage(systemName: "antenna.radiowaves.left.and.right")
                    cell.slider.minimumValue = 5
                    cell.slider.maximumValue = 100

                }.onChange { row in
                    let Barrel = Double(row.value ?? 50)
                    UserDefaultsManager.set(Barrel: Barrel)

                    ConnectionManager.reconnect()

                }
2

There are 2 best solutions below

0
vadian On

There is a property isContinuous in UISlider which controls the behavior.

.cellSetup { cell, row in
    cell.imageView?.image = UIImage(systemName: "antenna.radiowaves.left.and.right")
    cell.slider.minimumValue = 5
    cell.slider.maximumValue = 100
    cell.slider.isContinuous = false
0
Hans Maulwurf On
cell.slider.isContinuous = false

is half of the way, tanks for that
but it also disables the value update of the slider
so the user have "to guess" what value will be set

got it working with

cell.slider.addTarget(self, action: #selector(self.sliderDidEndSliding), for: [.touchUpInside, .touchUpOutside])

and

@objc private func sliderDidEndSliding() {
   //do some magic
}