2011-09-04 83 views
0

我试图让UISliders在不能使用时动画变灰。带alpha的UISlider动画

这里是我的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];  
} 

}

如果滑块的符号属性设置为@“”或@“e_none”,将是灰色滑块和原因它不是互动的。但是在某些情况下,行[self setValue:newValue animated:YES]似乎“取消”了setAlpha动画。

有没有什么办法可以同时设置滑块的值并使用UIView动画改变它的alpha值?

在此先感谢。

回答

0

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

[self setUserInteractionEnabled:NO];

[UIView beginAnimations:nil context:nil]; 

[UIView setAnimationDuration:0.5]; 

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

[UIView commitAnimations]; 

OR 我能想到的另一种方法是,你重写setValueAnimated方法和改变阿尔法在

+0

嗯。这不起作用,似乎每次更改滑块的值都会自动将alpha更改为1。 – chmod

+0

当你先设定值和alpha后会发生什么......? – Mohammad

+0

滑块的值将更改,但alpha将保持为1。 – chmod