In an iphone app, I would like to allow the user to tap a UISliderControl to decrement the slider by a fixed amount. How would I go about doing this?
Clarification: The user will be using sliders to adjust target numeric values at granularities that are too fine for the UISliderControl alone to set. So for example, a value could range from 0 to 1000, but the slider may only be able to cover 1/3rd of the values due to pixel constraints (ie, 0, 3, 6, 9). In this example, I would like to add a tap gesture to the slider th开发者_如何学Goat would decrement the target value by 1. So if the granularity of the slider only goes to 0, 3, 6, 9 and the user needs 7, he could move the slider to 9 and tap the slider twice.
Thanks
What you're looking for is called a UITapGestureRecognizer
. In the viewDidLoad
method of your controller, add this code:
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTapSlider:)];
[mySliderControl addGestureRecognizer:tap];
[tap release];
...then, add a method to your controller:
- (void)didTapSlider:(UITapGestureRecognizer *)tap
The didTapSlider:
method will be called when the user taps the UISlider, and the contents of tap
(in particular locationOfTouch:inView:
) will tell you the details. From there you can increment or decrement the slider's value as needed.
精彩评论