开发者

UISlider problem - how to detect a user releasing the slider button in iOS?

开发者 https://www.devze.com 2023-03-08 02:48 出处:网络
I can detect the value change event from the UISlider, but now I need to detect a user releasing 开发者_Go百科the slider button.

I can detect the value change event from the UISlider, but now I need to detect a user releasing 开发者_Go百科the slider button.

How to detect this event (or touch on slider ends) ?

Should I use the "touch up inside" event for detection ?

Thanks.


You can also use the UISlider's UIControlEventValueChanged. Set the continuous property to NO as to initiate when the user is done selecting a value.

[mySlider addTarget:self action:@selector(myMethod) forControlEvents:UIControlEventValueChanged];
mySlider.continuous = NO;


I've not worked with sliders, however as UISlider inherits from UIView - surely you can just tap into touchesBegan: and touchesEnded: to perform your task.


Through IB you can attach "Touch Up Inside" and "Touch Up Outside" to a method/action of the viewController for slider release.

Or more programmatically (probably in your viewController), you can use

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

to detect when the UIControlEventTouchUpOutside and UIControlEventTouchUpInside events occur to your UISlider.

References

  • method
  • control events


UIControlEventTouchDown event to detect when the user starts using the control. UIControlEventTouchUpInside when the user finishes using the slider. To add the event just do as @JohnK suggested

0

精彩评论

暂无评论...
验证码 换一张
取 消