快速提问,我的代码:
if (slider2.value == 1)
{
barHeight = 100;
}
else if (slider2.value == 2)
{
barHeight = 200;
}
else if (slider2.value == 3)
{
barHeight = 300;
}
else if (slider2.value == 4)
{
barHeight = 400;
}
else if (slider2.value == 5)
{
barHeight = 500;
}
else
{
barHeight = 600;
}
当我将滑块从 1 拖动到 6 时,我看到栏的高度发生了变化。但是当我从 6 移动到 1 时,barHeight 停留在 600 并且不会返回到 100。我错过了什么?
编辑(完整声明):
- (void)valueAgeChanged:(UISlider*)slider2
{
// DRAW BARS (skeme)
CGRect frame = CGRectMake(595, barX, 80, barHeight);
orangeView= [[UIView alloc] initWithFrame:frame];
orangeView.backgroundColor = [UIColor orangeColor];
[self.view addSubview:orangeView];
// Let slider 1 animate on set value
[slider2 setValue:((int)((slider2.value + 1) / 1.0) - 1.0) animated:NO];
if (slider2.value == 1) {
barHeight = 100;
}else if (slider2.value == 2) {
barHeight = 200;
// barX = 300;
}else if (slider2.value == 3) {
barHeight = 300;
}else if (slider2.value == 4) {
barHeight = 400;
}else if (slider2.value == 5) {
barHeight = 500;
}else if (slider2.value == 6) {
barHeight = 600;
}
}