Reputation: 17
i m new with iOS, and i want to know how to make my slider to react only when the the touch is ended. i figure that out with the method:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
But i can't make it work.
Does anyone can help me with simple & clear example?
Please, answer programmatically, i don't use storyBoard.
Thanks in advance!!!
Upvotes: 0
Views: 680
Reputation: 571
You have to set the property continuous.
Contains a Boolean value indicating whether changes in the sliders value generate continuous update events.
mySlider.continuous= NO;
Upvotes: 0
Reputation: 4899
You could hook up UIControlEventTouchUpInside
and -Outside
instead of -ValueChanged
(if you're doing that right now).
Edit: or, al little more elegant I would say, use UIControlEventValueChanged
, but also have the event provided as a parameter to your method:
[self.slider addTarget:self action:@selector(handleValueChanged:withEvent:) forControlEvents:UIControlEventValueChanged];
And then check the phase of the touch, to see if it's in the ended
state.
Upvotes: 0
Reputation: 17
Found the answer!
these guys helped me alot: Detecting touches on a UISlider?
with a small accuracy:
the action for the relevant slider assign to him as:
[self.slider addTarget:self action:@selector(touchEnded:) forControlEvents:UIControlEventTouchUpInside | UIControlEventTouchUpOutside];
and the method signature is:
- (IBAction)touchEnded:(id) sender
with storyboard it seems to me a bit different to assign the action to the slider.
Thanks for the answers!
Upvotes: 0
Reputation: 21726
You can add gesture recognizer:
UITapGestureRecognizer *tapGestureRecognizer = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onSliderTap:)] autorelease];
[slider addGestureRecognizer:tapGestureRecognizer];
- (void)onSliderTap:(UIGestureRecognizer *)gestureRecognizer {
// handle event
}
or add some action on slider:
[slider addTarget:self action:@selector(onTouchEnded:) forControlEvents:UIControlEventTouchUpInside];
Upvotes: 1