是否有任何更好的方法来使UISliders值以对数而不是线性方式变化?因此,例如,值在滑块的前半部分从0到25,在下半部分从25到100。
发布于 2012-05-30 00:49:35
不幸的是没有。但是,您可以将滑块给出的float值转换为所需的数字。下面是一个例子。
float interpretedValue;
if (sliderValue < 0.5) {
interpretedValue = sliderValue * 25 / 0.5;
} else {
interpretedValue = (sliderValue - 0.5)*(100 - 25)/0.5 + 25;
}我在方程中留下了一些常量,这样你就可以更容易地调整。但是为了最大限度地提高性能,我会简化它们。
编辑,2013年1月17日:
我被要求提供一组方程,它可以在给定解释值的情况下找到滑块值。下面是它们:
float sliderValue;
if (interpretedValue < 25) {
sliderValue = interpretedValue * 0.5 / 25;
} else {
sliderValue = (interpretedValue - 25) * 0.5 / (100 - 25) + 0.5;
}https://stackoverflow.com/questions/10808604
复制相似问题