2009-06-15 5 views
3

私はUIImageView(1)がフェードインし、(2)動き、(3)画面から滑り落ちるように多段階アニメーションをしようとしています。多段UIImageViewアニメーションの作成方法は?

ステージ1のみ動作するようです。私は間違って何をしていますか?

[UIView setAnimationDelegate:self]; 

(nilに設定)デリゲートとして自分自身の設定を解除するために良いでしょうで:あなたはアニメーションデリゲートとして自分自身を設定するための呼び出しを追加する必要があります

// FIRST PART - FADE IN 
-(void)firstAnim 
{ 
    // 'sprite' is a UIImageView 
    [sprite setAlpha:0.1f]; 
    [UIView beginAnimations:@"anim1" context:NULL]; 
    [UIView setAnimationBeginsFromCurrentState:YES]; 
    [UIView setAnimationDuration:0.25]; 
    [UIView setAnimationDidStopSelector:@selector(secondAnim)]; 
    [UIView setAnimationCurve:UIViewAnimationCurveLinear]; 
    [sprite setAlpha:1.0f]; 
    [UIView commitAnimations]; 
} 


// SECOND PART - MOVE 
-(void)secondAnim 
{ 
    [UIView beginAnimations:@"anim2" context:NULL]; 
    [UIView setAnimationBeginsFromCurrentState:YES]; 
    [UIView setAnimationDuration:0.5]; 
    [UIView setAnimationDidStopSelector:@selector(thirdAnim)]; 
    [UIView setAnimationCurve:UIViewAnimationCurveLinear]; 
    sprite.frame = CGRectMake(170, 184, 20, 20); 
    [UIView commitAnimations]; 
} 

// THIRD PART - SLIDE OFF SCREEN 
-(void)thirdAnim 
{ 
    [UIView beginAnimations:@"anim3" context:NULL]; 
    [UIView setAnimationBeginsFromCurrentState:YES]; 
    [UIView setAnimationDuration:0.5]; 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
    sprite.frame = CGRectMake(170, 420, 20, 20); 
    [UIView commitAnimations]; 
} 

答えて

4

:ここでは、コードです最後のアニメーションブロック。

+0

感謝を使用しています。私もsetAnimationDidStopSelector行にしなければなりません:[UIView setAnimationDidStopSelector:@selector(secondAnim:finished:context :)]; – cannyboy

4

あなたの質問への完全なソリューションです:

1)は、アニメーションデリゲート

2セット)、正しい選択とメソッドシグネチャに

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:.5]; 
[UIView setAnimationDelegate:self]; //set delegate! 
[UIView setAnimationDidStopSelector: 
    @selector(secondAnim:finished:context:)]; 


-(void)secondAnim:(NSString *)animationID 
     finished:(NSNumber *)finished 
      context:(void *)context { 

    //animation #2 
} 
関連する問題