在价值处停止UISlider [英] Stop UISlider at Value

查看:83
本文介绍了在价值处停止UISlider的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UISlider,我希望它停在某个值。这不是最大值,而是以编程方式提供的数字。

I have a UISlider and I want it to stop at a certain value. This is not the maximum, but a number that is available programmatically.

示例:UISlider的最大值为100.停止值为60.因此,用户不应该'我能够拖动超过60。

Example: UISlider has max value of 100. The stop value is 60. Therefore, the user shouldn't be able to drag beyond 60.

我现在使用的方法是添加一个带有选择器功能的动作,然后我会将值更改为停止的位置。

The method I'm using right now is to add an action with a selector function, and there I would change the value back to the stopped position.

[mySlider addTarget:self action:@selector(modifySliderValue) forControlEvents:UIControlEventValueChanged];

...

- (void)modifySliderValue{
    if(mySlider.value > 60) {
        mySlider.value = 60;
    }
}

由于滑块出现故障,这不能正常工作。它一直试图跳过60分,看起来不对。

This doesn't work well as the slider appears glitchy. It keeps trying to skip past the 60 mark and it doesn't look right.

实现这一目标的最佳方法是什么?

What is the best way to achieve this?

推荐答案

我通过使用UIControlEventAllEvents而不是UIControlEventValueChanged找到了一个简单的解决方案。

I found an easy solution by using UIControlEventAllEvents instead of UIControlEventValueChanged.

这篇关于在价值处停止UISlider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆