Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: Get the final value of UISlider after user releases the finger

Tags:

ios

uislider

In my iOS app (8.1). I have a UISlider which continuous property is set to YES (because I need to update labels dynamically).

My problem is that I also need to send the value picked and send it to the server. So in my case right now it does it all the time.

Can I somehow get only the last value? The value after the user releases the finger?

Any kind of help is highly appreciated.

P.S. I looked through a lot of solutions on Stackoverflow, like touchesBegan/ended, linking events in the NIB but nothing works so far.

like image 553
Eugene Gordin Avatar asked Nov 03 '14 22:11

Eugene Gordin


2 Answers

Yu can connect multiple actions to a single control, including a slider. In addition to the one you have for "value changed", create another method hooked up to "touch up inside", and grab the slider's value in that method.

- (IBAction)dragged:(UISlider *)sender { // value changed
    NSLog(@"here");
    // update labels continuously here
}


- (IBAction)endedDragging:(UISlider *)sender { // touch up inside
    NSLog(@"value is %f",sender.value);
    //grab the final value here
}
like image 52
rdelmar Avatar answered Sep 28 '22 10:09

rdelmar


Add a IBAction to listen ValueChanged events and uncheck UISlider's "Continuous Updates" property from Storyboard.

like image 22
anshuman Avatar answered Sep 28 '22 09:09

anshuman