Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

swift

uislider

I need to read each and every value of a UISlider. 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)

code:

@IBAction func didMoveFeedbackSlider(sender: UISlider) {

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

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

}
like image 308
Meurig Avatar asked Sep 13 '16 15:09

Meurig


1 Answers

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 +=
        print(value)
    }
}

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 :)

like image 106
Lachezar Todorov Avatar answered Oct 17 '22 00:10

Lachezar Todorov