4

UILabels数秒後に次々とフェードアウトしたいものが3つあります。私の問題は、これらがすべて同時に起こっていることです。アニメーションを連鎖させようとしていますが、これを機能させることができません。私はあらゆる種類の提案を試みましたが、役に立ちませんでした。私はそれがそれほど難しいことではないことを知っています。animationDidStop3 つのラベルすべてが表示された後に他の機能をトリガーしたいので、これらを 1 つのアニメーション メソッドにまとめたいと考えています。ヘルプや提案はありますか??

これが私のコードです:

- (void)viewDidLoad
{
    [self fadeAnimation:@"fadeAnimation" finished:YES target:lblReady];
    [self fadeAnimation:@"fadeAnimation" finished:YES target:lblSet];
    [self fadeAnimation:@"fadeAnimation" finished:YES target:lblGo];
}


- (void)fadeAnimation:(NSString *)animationID finished:(BOOL)finished target:(UIView *)target
{
    [UIView beginAnimations:nil context:nil];
    [UIView beginAnimations:animationID context:(__bridge void *)(target)];
    [UIView setAnimationDuration:2];

    [target setAlpha:0.0f];
    [UIView setAnimationDelegate:self];    
    [UIView commitAnimations];
}
4

2 に答える 2

8

これは、最新のUIViewアニメーション メソッドを使用すると簡単になります。

[UIView animateWithDuration:2.0 animations:^ {
    lblReady.alpha = 0;
} completion:^(BOOL finished) {
    [UIView animateWithDuration:2.0 animations:^ {
        lblSet.alpha = 0;
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:2.0 animations:^ {
            lblGo.alpha = 0;
        } completion:^(BOOL finished) {
            // Add your final post-animation code here
        }];
    }];
}];
于 2013-03-20T03:43:28.453 に答える
1

代わりに performSelector:withObject:afterDelay: を使用する必要があります。

コードを次のように変更します。

- (void)viewDidLoad
{
    [self performSelector:@selector(fadeAnimation:) withObject:lblReady afterDelay:0];
    [self performSelector:@selector(fadeAnimation:) withObject:lblSet afterDelay:2];
    [self performSelector:@selector(fadeAnimation:) withObject:lblGo afterDelay:4];
}

-(void)fadeAnimation:(UIView *)target {
    [self fadeAnimation:@"fadeAnimation finished:YES target:target];
}




- (void)fadeAnimation:(NSString *)animationID finished:(BOOL)finished target:(UIView *)target
{
    [UIView beginAnimations:nil context:nil];
    [UIView beginAnimations:animationID context:(__bridge void *)(target)];
    [UIView setAnimationDuration:2];

    [target setAlpha:0.0f];
    [UIView setAnimationDelegate:self];    
    [UIView commitAnimations];
}

これは、0、2、または 4 セクションの後に各アクション コードを呼び出すだけです。アニメーションの長さが変更された場合、それらの数値もそれに応じて変更する必要があります。

古いアニメーション スタイルを使用する代わりにブロック アニメーションを使用する場合は、代わりに次のようにします。

[UIView animateWithDuration:2 animations ^{
    //put your animations in here
} completion ^(BOOL finished) {
    //put anything that happens after animations are done in here.
    //could be another animation block to chain animations
}];
于 2013-03-20T03:41:27.850 に答える