Reputation: 229
I want to know how to identify the UISlider is tracking towards maximum to its minimum values? For ex, My slider maximum and minimum values 1.0 and 0.0. How can I identify my slider is tracking from 0.0 to 1.0 and vice versa?
Thanks!
Upvotes: 1
Views: 589
Reputation: 977
There is an event of UISlider named value changed. Use that event and calculate the difference. If difference is positive then its going towards max value otherwise its moving towards min value. Use below action method.
- (IBAction)sliderdidchanged:(UISlider *)sender {
if (sliderOldValue - sender.value > 0) {
NSLog(@"Value Decreasing");
}
else {
NSLog(@"Value Increasing");
}
sliderOldValue = sender.value;
}
Don't forget to make reference to this method from UISlider object in your xib or Storyboard. Also declare sliderOldValue as instance variable and in viewDidLoad assign its value to the slider's default value.
Upvotes: 1
Reputation: 25692
.h
To track Last Value
@property(nonatomic,assign) float lastValue;
.m
in ViewDidLoad listen for UIControlEventValueChanged
[yourSlider addTarget:self
action:@selector(mySliderValueChanged:)
forControlEvents:UIControlEventValueChanged];
Define the method
- (IBAction)mySliderValueChanged:(UISlider *)sender {
float currentValue = sender.value;
if (currentValue>self.lastValue) {
NSLog(@"moving Right");
}
else{
NSLog(@"moving Left");
}
self.lastValue = sender.value;
}
Upvotes: 0
Reputation: 25619
You can listen for the ValueChanged control event
[slider_ addTarget:self action:@selector(sliderMove:) forControlEvents:UIControlEventValueChanged];
...
- (void) sliderMove:(UISlider*)slider
{
if (slider.value == slider.minimumValue) {
// etc...
}
else if (slider.value == slider.maximumValue) {
// so on and so forth
}
}
Upvotes: 0