CALayerを使わない、UIViewアニメの停止/再開2012年07月20日 10:25

UIViewのアニメーションはサンプル例も多く作りやすいが、アニメーションの停止、再開をコントロールしたい場合、CALayerを扱ううことになって面倒になるようである。
目的にもよるが、例えばボタン等のUI部品の点滅アニメーションの場合は、CALayerを扱わなくても容易に実現できた。

// 点滅アニメーション
-(void) flashAnimation:(BOOL)start
{
 [UIView beginAnimations:nil context:NULL];
 [UIView setAnimationDuration:0.3f];
 [UIView setAnimationCurve:UIViewAnimationCurveLinear];

 if (start) {
  // -点滅開始-
  [UIView setAnimationDuration:0.8f];
  [UIView setAnimationRepeatCount:1000];
  [UIView setAnimationRepeatAutoreverses:YES];
  [button_ setAlpha:0.5f];
 } else {
  // -点滅停止-
  [UIView setAnimationBeginsFromCurrentState:YES];
  [UIView setAnimationRepeatCount:1];
  [button_ setAlpha:1.0f];
 }
 [UIView commitAnimations];
}

参考サイト:
http://stackoverflow.com/questions/6893181/how-to-flash-a-button-on-ui-thread