0

このアニメーションが終了するたびにメソッドを呼び出そうとしていますが、ユーザーがアプリケーションを終了したときなどに完了ブロックが呼び出されないことがあります。 また、UIViewアニメーションと同時にアニメーションを含むVCが表示されると、完了ブロックが呼び出されることはありません。アニメーションが中断されたときにUIViewアニメーション完了ブロックが呼び出されない

何とかアニメーションが中断してもコールバックが呼び出されるようにするにはどうすればよいですか? UIViewアニメーション補完ブロックをまったく使用しないでください。私を啓発してください..!

-(void)action { 

[UIView animateWithDuration:0.3 
         delay:0.0 
        options:UIViewAnimationOptionCurveEaseOut 
       animations:^{ 

        self.doorLeft.frame = CGRectMake(0, 0, self.doorLeft.frame.size.width, self.doorLeft.frame.size.height); 
        self.doorRight.frame = CGRectMake(self.frame.size.width -self.doorRight.frame.size.width, 0, self.doorRight.frame.size.width, self.doorRight.frame.size.height); 

       } completion:^(BOOL finished){ 
        if (finished) { 
         switch (self.type) { 
          case 0: 
           [self.delegate startTOship]; 
           break; 
          case 1: 
           [self.delegate gameTOship]; 
           break; 
          case 2: 
           [self.delegate shipTOgame]; 
           break; 
          case 3: 
           [self.delegate shipTOmap]; 
           break; 
          case 4: 
           [self.delegate gameTOmap]; 
           break; 
          case 5: 
           [self.delegate mapTOgame]; 
           break; 
          case 6: 
           [self.delegate mapTOship]; 
           break; 
         } 

         [UIView animateWithDuration:0.3 
               delay:0.5 
              options:UIViewAnimationOptionCurveEaseOut 
              animations:^{ 

               self.doorLeft.frame = CGRectMake(-self.doorLeft.frame.size.width, 0, self.doorLeft.frame.size.width, self.doorLeft.frame.size.height); 
               self.doorRight.frame = CGRectMake(self.doorRight.frame.size.width *2, 0, self.doorRight.frame.size.width, self.doorRight.frame.size.height); 

              } completion:^(BOOL finished){ 
               if (finished) { 

                [self actionEnded]; 
               } 
              } 
          ]; 
        } 
       } 
];} 

答えて

0

代わりにCATransactionを使用してください。

[CATransaction begin]; 

[CATransaction setCompletionBlock:^{ 
    [self actionEnded] 
}]; 

[UIView animateWithDuration:8.3 delay:0.5 options:UIViewAnimationOptionCurveEaseOut animations:^{ 

    self.doorLeft.frame = CGRectMake(-self.doorLeft.frame.size.width, 0, self.doorLeft.frame.size.width, self.doorLeft.frame.size.height); 
    self.doorRight.frame = CGRectMake(self.doorRight.frame.size.width *2, 0, self.doorRight.frame.size.width, self.doorRight.frame.size.height); 

} completion:nil]; 

[CATransaction commit]; 

アニメーションがまったく中断された場合は、完了ブロックはアニメーションが途切れない完了時にブロックとも呼ばれ、ほとんどすぐに呼ばれています。

P.S:CATransactionはすべてUIViewアニメーションで動作します。アニメーションが起こる前にbeginと言って、アニメーションコードの後に​​commitと言う限り。

+0

私が編集した質問のように複数のアニメーションを次々と持つ「連鎖」アニメーションを持っているとどうなりますか? – durazno

+0

最後のアニメーションコードの後に​​コミットブロックを追加します。 – Tander

+0

しかし、私はCAKeyframeAnimationをやっていなければならないと思っています。 CAKeyframeAnimationは、アニメーションが中断されたときに完了ブロックがすぐに呼び出されるようにするか、CATransitionと一緒に使用する必要がありますか? – durazno

関連する問題