CoreAnimation で View を点滅させてみる。
- (void)blinkImage:(UIImageView *)target {
CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
animation.duration = 1.0f;
animation.autoreverses = YES;
animation.repeatCount = HUGE_VAL;
animation.fromValue = [NSNumber numberWithFloat:1.0f];
animation.toValue = [NSNumber numberWithFloat:0.5f];
[target.layer addAnimation:animation forKey:@"opacityAnimation"];
}
CABasicAnimation で opacity を設定。 無限ループは HUGE_VAL 定数を利用する。
--2012/05/19追加
- (void)blinkImage:(UIImageView *)target {
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"opacity"];
animation.duration = 1.0f;
animation.repeatCount = HUGE_VAL;
animation.values = [[NSArray alloc] initWithObjects:
[NSNumber numberWithFloat:1.0f],
[NSNumber numberWithFloat:0.0f],
[NSNumber numberWithFloat:1.0f],
nil];
[target.layer addAnimation:animation forKey:@"blink"];
}