2011-09-04 57 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