[英]Disable UISlider from sliding, but still allow it to receive UIControlEventTouchDown
有沒有辦法禁用UISlider
滑動,但要讓它的UIControlEventTouchDown
觸發? 我認為可以做的一種方法是將滑塊起始值設置為與結束值相同,但我想避免這樣做。 有誰知道更好的方法?
我建議為你的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];
然后根據您想要啟用滑塊的任何條件,您可以啟用它並禁用該按鈕。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.