Objective-c – UISlider events

eventsiphoneobjective cuislider

I'm using an UISlider, its updated automatically except the user is touching the sliderbutton. therefore i did this in the function which updates automatically by an NSTimer:

if (!isSliderTouched) {
    [progressSlider setValue: progressValue];
}

How do I track the ending of this event, when the user releases his finger. I want to set isSliderTouched as long as the user interacts with this control.

EDIT: this should be the plot:

  1. user beginns draging/touching UISlider => isSliderTouched = YES
  2. user releases/untouch the UISlider => isSliderTouched = NO

Solution:

UIControlEventTouchDown
UIControlEventTouchUpInside
[progressSlider addTarget:self action:@selector(sliderMoveStart) forControlEvents:UIControlEventTouchDown];

cheers endo

Best Answer

You can use:

- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents

to detect when the touchDown and touchUp events occur. You can set your flag accordingly.

I'm guessing from your code snippet that you are using a UISlider as a progress meter. Have you considered using a UIProgressView instead?