Meurig Meurig - 1 year ago 75
Swift Question

How to read every value of a UISlider regardless of how quickly the slider is moved?

I need to read each and every value of a

. When I print the value of the slider in the debug area you will see that every value is incremented by 1 when moving the slider at slow-medium pace.

Slider values at slow-medium pace

However when I move the slider fast the values jump in large steps as seen below:

Slider values at fast pace

Is there anyway I can read the value of a slider with every step regardless of the speed at which it is moved? (preferably in swift)


@IBAction func didMoveFeedbackSlider(sender: UISlider) {

let currentValue = sender.value
var currentValueInt = Int(ceil(currentValue))

print("slider value: \(currentValueInt)")


Answer Source

OK, if you want to follow your algorithm here is a possible solution

var value:Int = 0
func readSliderValue(val:Int) {
    while(value != val) {
        value = value + (val < value ? -1 : 1) // or use +=

But Probably Matt is right and the problem is in the design and/or algorithm.

Why the values are not sequential: The slider represents the actual value of the slider by your mouse/finger position. When you move your finger really fast as on your video/gif the internal process that scans for your finger position/gesture is slower than your finger. So between two checks of the internal algorithms for finger position it(your finger) crossed more than one position of the slider. So the idea of the slider is not to show you how your finger got there, but where it is now. So the slider is working correctly, from it's creators perspective :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download