2011-08-09 29 views
-1

我有這樣的代碼,其中successview阿爾法開始= 0.00IOS:阿爾法問題

- (void) startAnimation{ 
    //immediately 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:3]; 
    [successView setAlpha:1.00]; 
    [UIView commitAnimations]; 
    //in three seconds 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:3]; 
    [successView setAlpha:0.00]; 
    [UIView commitAnimations]; 
} 
這樣

,在第一動畫(阿爾法0.00〜1.00),但不要在3秒鐘內發生,但立即,在第二動畫(阿爾法1.00至阿爾法0.00),而不是它發生在3秒內

如果我只寫firts動畫:

- (void) startAnimation{ 
    //in three seconds 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:3]; 
    [successView setAlpha:1.00]; 
    [UIView commitAnimations]; 
} 

它發生在3秒內,爲什麼在福斯特例如,它不要會發生嗎?

+0

可能重複(http://stackoverflow.com/questions/6997659/ios-uiviewimage-setalpha-problem) –

+1

不要重複問同樣的問題,但編輯原始內容包含您提供的新信息。 –

回答

0
- (void)startAnimation 
{ 
    [UIView beginAnimations:@"successAnimationPart1" context:nil]; 
    [UIView setAnimationDuration:3]; 
    [UIView setAnimationDelegate:self]; 
    [successView setAlpha:1.00]; 
    [UIView commitAnimations]; 
} 

並添加此動畫的委託方法:

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context 
{ 
    if ([animationID isEqualToString:@"successAnimationPart1"]) { 
     // when first animation is done, call second 
     [UIView beginAnimations:@"successAnimationPart2" context:nil]; 
     [UIView setAnimationDuration:3]; 
     [UIView setAnimationDelegate:self]; 
     [successView setAlpha:0.00]; 
     [UIView commitAnimations]; 
    } 
} 
[IOS:UIViewImage setAlpha問題]的
0

你可以嘗試設置動畫延遲你的第二動畫(請注意,使用此API灰心,你應該使用基於塊的animateWithDuration:delay:options:animations:completion:動畫,如果你的目標IOS4.0 +):

... 
[UIView setAnimationDelay:3.0]; 
... 

但如果你只是想查看的alpha更改爲1,並且將其恢復您可以使用只是你的第一個動畫,但使其autoreversing:

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:3]; 
[UIView setAnimationRepeatAutoreverses:YES]; 
[successView setAlpha:1.00]; 
[UIView commitAnimations]; 
+0

NO ...在動畫結尾我有alpha = 1.00爲什麼? – CrazyDev