带有alpha的UISlider动画

时间:2011-09-04 15:24:43

标签: iphone animation uiview uislider

我正在尝试制作UISliders,当它们无法使用时,动画会变灰。

以下是我的UISlider子类中的代码:

    - (void)setSymbol:(NSString *)s {
symbol = s;

float newValue = [[S76PresetManager sharedManager] getValueForKey:symbol];
[self setValue:newValue animated:YES];  

if (symbol == @"" || symbol == @"e_none") {
    // gray out the slider
    [self setUserInteractionEnabled:NO];
    [UIView beginAnimations:nil context:nil];       
    [UIView setAnimationDuration:0.5];

    [self setAlpha:0.5];

    [UIView commitAnimations];

} else {
    // reactivate the slider
    [self setUserInteractionEnabled:YES];
    [UIView beginAnimations:nil context:nil];       
    [UIView setAnimationDuration:0.5];

    [self setAlpha:1.0];

    [UIView commitAnimations];      
}

}

如果滑块的symbol属性设置为@“”或@“e_none”,它将使滑块变灰并使其不是交互式的。但是,在某些情况下,行[self setValue:newValue animated:YES]似乎“取消”了setAlpha动画。

有什么方法可以同时设置滑块的值并使用UIView动画更改其alpha值?

提前致谢。

2 个答案:

答案 0 :(得分:0)

我不确定这个......但是也许按照以下方式编写代码可能有所帮助。

[self setUserInteractionEnabled:NO];

[UIView beginAnimations:nil context:nil];

[UIView setAnimationDuration:0.5];

self.alpha = 0.5;
self.value = newValue;

[UIView commitAnimations];

[UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.5]; self.alpha = 0.5; self.value = newValue; [UIView commitAnimations];

OR 我能想到的另一种方法是覆盖setValueAnimated方法并更改

中的alfa

答案 1 :(得分:0)

UISlider中存在一个错误,导致忽略alpha值0.5。

UISlider ignores alpha when set to 0.5

我将[self setAlpha:0.5]更改为[self setAlpha:0.49]并按预期工作。

相关问题