UISlider too sensitive when releasing touch

佐手、 提交于 2019-12-14 02:16:36

问题


When releasing the touch on a UISlider the value of the slider changes slightly and uncontrollably. It's so sensitive that it even changes when just releasing the finger from the screen. How can I achieve that the user can set a value he wants without problems?

That's how I create my UISlider:

UISlider *slider = [[UISlider alloc] initWithFrame: CGRectMake(100.0, 100.0, 200.0, 40.0)];
slider.minimumValue = 0.0;
slider.maximumValue = 100.0;
[slider addTarget: self action: @selector(sliderChanged:event:) forControlEvents:UIControlEventAllEvents];
[slider setValue: 50.0 animated: NO];

回答1:


You are registering it for all events. Make it for your event only like

[slider addTarget: self action: @selector(sliderChanged:event:) forControlEvents: UIControlEventTouchDragInside];



回答2:


Try changing it to this instead:

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

And if all you want is to trigger the target only when the finger is lifted, try setting continuous property of the UISlider to NO.



来源:https://stackoverflow.com/questions/22147068/uislider-too-sensitive-when-releasing-touch

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!