2

I'm using the following code to know a slider is now sliding or not.
But is there a property or method to know that more easily?

[slider addTarget:self action:@selector(touchUp) forControlEvents:UIControlEventTouchUpInside];
[slider addTarget:self action:@selector(touchUp) forControlEvents:UIControlEventTouchUpOutside];
[slider addTarget:self action:@selector(touchUp) forControlEvents:UIControlEventTouchCancel];            
[slider addTarget:self action:@selector(touchDown) forControlEvents:UIControlEventTouchDown];

- (void)touchDown {
    self.sliding = YES;
}

-(void)touchUp {
    self.sliding = NO;
}
js_
  • 4,671
  • 6
  • 44
  • 61
  • 1
    if you want to know whether the value of the slider changed or not (sliding or not), you can listen to UIControlEventValueChanged -- here's an example I found on SO http://stackoverflow.com/questions/4093143/what-gets-called-when-a-uislider-value-changes – ewiinnnnn Jun 25 '12 at 10:16
  • thank you. but I know that event. I'm using slider for volume. And I also use volume changed notification. I want to ignore the notification while I'm sliding volume slider. – js_ Jun 25 '12 at 10:41

2 Answers2

5

There is a property you can use.

slider.highlighted 

This property will have value YES when you are holding it down.

Geebs
  • 199
  • 2
  • 4
3
- (void)touchDown { self.sliding = YES; }
- (void)touchUp   { self.sliding = NO;  }

Using booleans is indeed the common way to track user interaction on sliders.

But is there a property or method to know that more easily?

No, not as far I'm aware.

Anne
  • 26,765
  • 9
  • 65
  • 71