【问题标题】:Disable UISlider from sliding, but still allow it to receive UIControlEventTouchDown禁止 UISlider 滑动,但仍然允许它接收 UIControlEventTouchDown
【发布时间】:2013-06-03 22:01:13
【问题描述】:

有没有办法禁止UISlider 滑动,但要让它的UIControlEventTouchDown 触发?我相信可以做到的一种方法是将滑块的起始值设置为与结束值相同,但我想避免这样做。有谁知道更好的方法吗?

【问题讨论】:

    标签: iphone ios cocoa-touch uislider


    【解决方案1】:

    我建议为您的 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];
    

    然后根据您想要启用滑块的任何条件,您可以启用它并禁用按钮。

    【讨论】:

    • 您好,“myView”是什么? UIslider ?
    • myView 是 UISlider 添加到的任何视图。
    猜你喜欢
    • 2011-06-24
    • 2021-07-14
    • 2016-07-26
    • 1970-01-01
    • 1970-01-01
    • 2012-05-09
    • 2013-07-27
    • 1970-01-01
    • 2018-06-05
    相关资源
    最近更新 更多