我有这样的代码。 在值数组的末尾,可以看到我不透明度提供0.5。 但由于某些原因,当动画停止时,它再次闪烁,然后离开看法完全透明的。 有什么不对呢?
CALayer *layer = self.layer;
CAKeyframeAnimation *blinkAnim = [CAKeyframeAnimation animationWithKeyPath:@"opacity"];
blinkAnim.duration = 1.0;
//blinkAnim.repeatCount = 0;
blinkAnim.autoreverses = NO;
// keyframe times and values
// we want to start fully opaque, fade out, stay faded out and fade back in shortly before the end of the cycle
blinkAnim.keyTimes = [NSArray arrayWithObjects: [NSNumber numberWithFloat:0.0],
[NSNumber numberWithFloat:0.4],
[NSNumber numberWithFloat:0.6],
[NSNumber numberWithFloat:0.85],
[NSNumber numberWithFloat:1.0], nil];
blinkAnim.values = [NSArray arrayWithObjects: [NSNumber numberWithFloat:1.0],
[NSNumber numberWithFloat:1.0],
[NSNumber numberWithFloat:0.0],
[NSNumber numberWithFloat:0.0],
[NSNumber numberWithFloat:0.5], nil];
[layer addAnimation:blinkAnim forKey:nil];