为什么这个 CAKeyFrameAnimation 会以零不透明度停止?
我有这个代码。 在值数组的末尾,您可以看到我提供了 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];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认
fillMode
(请参阅 此处)是kCAFillModeRemoved
。 您应该将动画的fillMode
设置为kCAFillModeForwards
,并将removedOnCompletion
属性设置为NO
(默认情况下)是的):您会注意到这些属性是在我为上一个问题编写的源代码中设置的 - 它们在那里是有原因的。
The default
fillMode
(see here) for aCAAnimation
iskCAFillModeRemoved
. You should set thefillMode
of your animation tokCAFillModeForwards
, and also set theremovedOnCompletion
property toNO
(by default it'sYES
):You'll notice that those properties were set in the source I wrote for your previous question -- they were there for a reason.