简体   繁体   中英

iPhone: How to know UISlider is sliding or not?

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;
}

There is a property you can use.

slider.highlighted 

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

- (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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM