如何使用延迟设置显式 CA 动画的最终值
Posted
技术标签:
【中文标题】如何使用延迟设置显式 CA 动画的最终值【英文标题】:How to set final value of explicit CA Animation with Delay 【发布时间】:2014-07-06 14:17:02 【问题描述】:我有一个明确的动画,我想在其中设置最终值,以便对象停留在终点。但是我如何在延迟动画上实现这一点:这是代码:
CAKeyframeAnimation *moveAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
moveAnimation.duration = 0.3;
moveAnimation.cumulative = YES;
moveAnimation.repeatCount = 1;
// Bounce
[moveAnimation setValues:[NSArray arrayWithObjects:
[NSValue valueWithCGPoint:[self getCoordinatePointForAnimationWithRadius:0 withIndex:i]],
[NSValue valueWithCGPoint:[self getCoordinatePointForAnimationWithRadius:radius + 10 withIndex:i]],
[NSValue valueWithCGPoint:[self getCoordinatePointForAnimationWithRadius:radius - 5 withIndex:i]],
[NSValue valueWithCGPoint:[self getCoordinatePointForAnimationWithRadius:radius withIndex:i]], nil]];
[moveAnimation setKeyTimes:[NSArray arrayWithObjects:
[NSNumber numberWithFloat:0],
[NSNumber numberWithFloat:0.5],
[NSNumber numberWithFloat:0.75],
[NSNumber numberWithFloat:1.0], nil]];
[moveAnimation setTimingFunctions:[NSArray arrayWithObjects:
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut], nil]];
moveAnimation.beginTime = CACurrentMediaTime() + 1 + (0.1 * i);
[layer addAnimation:opacityAnimation forKey:@"opacityAnimationUp"];
[layer addAnimation:moveAnimation forKey:@"moveAnimationUp"];
// That's not working correctly because of the delay
[layer setOpacity:1.0];
[layer setPosition:[self getCoordinatePointForAnimationWithRadius:radius withIndex:i]];
谢谢!
来自德国的问候, 克里斯
【问题讨论】:
【参考方案1】:看起来唯一缺少的是向后填充模式。这将导致动画在添加后立即显示第一个值,即使实际动画被延迟:
moveAnimation.fillMode = kCAFillModeBackwards;
【讨论】:
哇,成功了。谢谢大卫 (+1)以上是关于如何使用延迟设置显式 CA 动画的最终值的主要内容,如果未能解决你的问题,请参考以下文章