2011-08-03 17 views
4

ブロックレベルのテクニックを使ってアニメーションをやっています。私は一定の条件に基づいてアニメーションを停止したい。アニメーションの完成をどう止めるのですか?続き既に実行中のアニメーションを停止する方法

は、アニメーションのための私のコードです:

[UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction 
        animations:^{ 
         if([arrAns count]>0) 
          vwb1.center = CGPointMake(260, 40); 
        } 
        completion:^(BOOL finished){ 
         [UIView animateWithDuration:1.5 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction 
              animations:^{ 
               if([arrAns count]>1) 
                vwb2.center = CGPointMake(260, 100); 
              } 
              completion:^(BOOL finished){ 
               [UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction 
                   animations:^{ 
                    if([arrAns count]>2) 
                     vwb3.center = CGPointMake(260, 160); 
                   } 
                   completion:^(BOOL finished){ 
                    [UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction 
                        animations:^{ 
                         if([arrAns count]>3) 
                          vwb4.center = CGPointMake(260, 220); 
                        } 
                        completion:^(BOOL finished){ 
                         [UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ 
                          if([arrAns count]>4) 
                           vwb5.center = CGPointMake(260, 280); 
                         } completion:nil]; 
                        }]; 
                   }]; 

              } 
          ]; 

        }]; 

私はnnotキーに基づいて、それを削除することができますので、私はここに任意のキーを持っていないです。 removeallanimationという機能もありますが、使用できません。誰かがそれを使用する方法について私を助けることができれば、それはまたうまくいくでしょう。

編集:私はそれを行う方法を考え出し[OK]を、私は次のコード使用して、それをしています:

[self.view.layer removeAllAnimations]; 

をしかし、今、私はまだ開始していない私のブロックレベルのアニメーションがまだ実行されている問題を抱えています。したがって、2番目のブロックでアニメーションを削除すると、残りのブロックが実行されます。私もそれをやめる必要があります。

おかげ
パンカジ

+1

すべてのアニメーションを削除しましたか? –

+0

@Praveen今私のメッセージをチェックしてください。アップデートがあります... – pankaj

+0

すべてのレイヤーのアニメーションを別々に停止する必要があります。 –

答えて

2

あなたはfinished変数を確認する必要があります。また、前のアニメーションが終了した場合(ブロックfinished == YES)、停止しないで次のアニメーションを開始します。

+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion

...

完了
アニメーションシーケンス 端実行されるブロックオブジェクト。このブロックには戻り値がなく、完了ハンドラが呼び出される前にアニメーションが実際に 終了したかどうかを示す単一のブール 引数をとります。 の継続時間が0の場合、このブロックは、次の実行ループサイクル の開始時に実行されます。

関連する問題