UISlider behaviour in iOS7 versus iOS6

2019-02-03 16:49发布

问题:

I noticed that UISlider in iOS7 behaves differently than it did in iOS 6 and iOS 5:

Say you have a slider with min=0 and max=10, current value is 0. When you first touch the "knob", a valueChanged message is sent with slider.value=0.269 (instead of the expected 0) and the knob moves towards the middle. Generally, touching the slider moves it towards the middle value (5 in this example), the farther out from the middle it currently is, the more it moves.

All this did not happen in iOS6, and I'd like to restore the old behaviour, but have no idea how to achieve this.

回答1:

Apple has not commented on my bug report yet, but I've found a solution more or less by accident: installing a custom image for the knob restores the behaviour from iOS 6:

[self.slider setThumbImage:[UIImage imageNamed:@"knob"] forState:UIControlStateNormal];


回答2:

On iOS 9 you need to set for .Normal, .Selected and .Highlighted states to work. I found this after 5h of struggling. Way to go Apple!

[_sliderView setThumbImage:[UIImage imageNamed:@"knob"] forState:UIControlStateNormal];
[_sliderView setThumbImage:[UIImage imageNamed:@"knob"] forState:UIControlStateSelected];
[_sliderView setThumbImage:[UIImage imageNamed:@"knob"] forState:UIControlStateHighlighted];


回答3:

I tested it and can confirm the described behavior.

Interestingly, when the app is built using the iOS 6 SDK but the device/simulator still runs iOS 7 (in compatibility mode) the bug does not occur. So it seems that it's connected to the new look.

File a bug.



标签: ios uislider