[英]Disable UISlider from sliding, but still allow it to receive UIControlEventTouchDown
Is there a way to disable a UISlider
from sliding, but to get its UIControlEventTouchDown
to fire? 有没有办法禁用UISlider
滑动,但要让它的UIControlEventTouchDown
触发? One way it could be done I believe is to set the slider start value the same as the end value, but I'd like to avoid doing that. 我认为可以做的一种方法是将滑块起始值设置为与结束值相同,但我想避免这样做。 Does anyone know a better way? 有谁知道更好的方法?
I would suggest setting userInteractionEnabled = NO for your UISlider, and adding an invisible button to handle the TouchDown 我建议为你的UISlider设置userInteractionEnabled = NO,并添加一个隐藏按钮来处理TouchDown
UIButton *btnSlider = [UIButton buttonWithType:UIButtonTypeCustom];
btnSlider.frame = CGRectMake(slider.frame.origin.x, slider.frame.origin.y, slider.frame.size.width, slider.frame.size.height);
[btnSlider addTarget:self action:@selector(sliderTouched) forControlEvents:UIControlEventTouchDown];
btnSlider.backgroundColor = [UIColor clearColor];
[myView addSubview:btnSlider];
Then based on whatever condition you want to make the slider enabled, you can enable it and disable the button. 然后根据您想要启用滑块的任何条件,您可以启用它并禁用该按钮。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.