UISlider's editingDidEnd event is not working

2019-07-17 15:28发布

I want to trigger one method when sliding the UISlider is ended.I used "editingDidEnd"event of UISlider in xib and attached it to a IBAction method but the method is not being called.Can any one please help me how to know when sliding is ended on UISlider?

2条回答
Explosion°爆炸
2楼-- · 2019-07-17 15:56

You can attach to the "UIControlEventValueChanged" slider event instead and use the following code in your event handler:

  [slider addTarget:self action:@selector(handleValueChanged:event:) forControlEvents:UIControlEventValueChanged];

- (void)handleValueChanged:(id)sender event:(id)event {
     UITouch *touchEvent = [[event allTouches] anyObject]; // there's only one touch
     if (touchEvent.phase == UITouchPhaseEnded) { /* place your code here */ }}
查看更多
Lonely孤独者°
3楼-- · 2019-07-17 15:58

UISlider inherits from UIControl so you should be able to add and action on "UIControlEventTouchUpInside"

Try something like :

[slider addTarget:self action:@selector(sliderTouchUpInsideAction:) forControlEvents:UIControlEventTouchUpInside];

Hope this helps, Vincent

查看更多
登录 后发表回答