CA关键帧动画
您好,我正在从多个图像创建关键帧动画。我的问题是我希望动画立即从一个图像变为下一个图像而不是淡入淡出。
CALayer *animLayer = [CALayer layer];
animLayer.bounds = CGRectMake(0, 0, width, height);
animLayer.position = CGPointMake(0, 0);
CAKeyframeAnimation *customFrameAnimation = [CAKeyframeAnimation animationWithKeyPath:@"contents"];
NSArray *sizeValues = [NSArray arrayWithObjects:(id)image1, (id)image2, nil];
NSArray *times = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0f], [NSNumber numberWithFloat:0.5f], nil];
NSArray *timingFunctions = [NSArray arrayWithObjects: [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault], [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault], nil];
[customFrameAnimation setValues:sizeValues];
[customFrameAnimation setKeyTimes:times];
customFrameAnimation.duration=5.0;
customFrameAnimation.beginTime = 1e-100;
customFrameAnimation.fillMode = kCAFillModeRemoved;
customFrameAnimation.timingFunctions = timingFunctions;
customFrameAnimation.removedOnCompletion = YES;
[animLayer addAnimation:customFrameAnimation forKey:nil];
提前致谢。
Hi i'm creating a Keyframe animation from multiple images. My problem is i would like the animation to instantly change from one image to the next rather than a fade.
CALayer *animLayer = [CALayer layer];
animLayer.bounds = CGRectMake(0, 0, width, height);
animLayer.position = CGPointMake(0, 0);
CAKeyframeAnimation *customFrameAnimation = [CAKeyframeAnimation animationWithKeyPath:@"contents"];
NSArray *sizeValues = [NSArray arrayWithObjects:(id)image1, (id)image2, nil];
NSArray *times = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0f], [NSNumber numberWithFloat:0.5f], nil];
NSArray *timingFunctions = [NSArray arrayWithObjects: [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault], [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault], nil];
[customFrameAnimation setValues:sizeValues];
[customFrameAnimation setKeyTimes:times];
customFrameAnimation.duration=5.0;
customFrameAnimation.beginTime = 1e-100;
customFrameAnimation.fillMode = kCAFillModeRemoved;
customFrameAnimation.timingFunctions = timingFunctions;
customFrameAnimation.removedOnCompletion = YES;
[animLayer addAnimation:customFrameAnimation forKey:nil];
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的动画需要将其计算模式设置为 kCAAnimationDiscrete。
看看 keyTimes 文档 描述了如何使用calculationMode:
然后你可以阅读计算模式的说明:
换句话说,离散计算模式使动画跳转到每个关键帧,而不是对其进行动画/过渡。
此致。
Your animation will need its calculationMode set to kCAAnimationDiscrete.
Take a look at the documentation on keyTimes which describes how the calculationMode is used:
And then you can read the description of the calculation modes:
In other words, the discrete calculation mode makes the animation jump to each key frame rather than animate/transition to it.
Best regards.