CABasicAnimation 在开始之前停止?
我需要淡入我的 CALayers。这是我的代码:
for(int i = 0; i < viewArray.count; i++)
{
CABasicAnimation *fadeIn = [CABasicAnimation animationWithKeyPath:@"opacity"];
fadeIn.duration = 0.3;
fadeIn.beginTime = i;
fadeIn.fromValue = [NSNumber numberWithFloat:0.0];
fadeIn.toValue = [NSNumber numberWithFloat:0.8];
fadeIn.removedOnCompletion = NO;
fadeIn.delegate = self;
[((CALayer*)[viewArray objectAtIndex:i]) addAnimation:fadeIn forKey:nil];
}
但是,只有前两个对象正确褪色,所有其他对象根本不褪色。我注意到,当我在animationDidStop 处放置断点时,大多数尚未开始的动画已经停止(即使是应该在 60 秒内开始的动画也会在前几秒内停止)。我不太确定发生了什么事。当我手动将每个 CALayer 的不透明度设置为 1 时,我可以正确看到它,但在制作动画时却看不到它。
I need to fade in my CALayers. Here's my code:
for(int i = 0; i < viewArray.count; i++)
{
CABasicAnimation *fadeIn = [CABasicAnimation animationWithKeyPath:@"opacity"];
fadeIn.duration = 0.3;
fadeIn.beginTime = i;
fadeIn.fromValue = [NSNumber numberWithFloat:0.0];
fadeIn.toValue = [NSNumber numberWithFloat:0.8];
fadeIn.removedOnCompletion = NO;
fadeIn.delegate = self;
[((CALayer*)[viewArray objectAtIndex:i]) addAnimation:fadeIn forKey:nil];
}
However, only the first two objects properly fades, all other objects do not fade at all. I've noticed that when I put a breakpoint at animationDidStop, most of the animations that have not started already stopped (even the animations that are supposed to start 60 seconds in are stopped within the first couple of seconds). I'm not exactly sure what's going on. I can see it properly when I manually set each CALayer's opacity to 1 but not when animating.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将同时启动所有动画,因为对
addAnimation:forKey:
的调用不会同步等待动画完成。我已经检查过了,看来你必须按以下方式设置 beginTime
You are starting all of the animations at the same time, because the call to
addAnimation:forKey:
does not synchronously wait until the animation is complete.I have checked it and it seems you have to set the beginTime in a following way