ios – 核心动画图像序列

ios – 核心动画图像序列,第1张

概述我将如何创建具有核心动画的图像序列.我想要: 添加image1 1秒钟然后删除图像 添加image2 2秒钟然后删除图像 添加image1 3秒钟然后删除 CGImageRef image1 = [self getImage1]; CALayer *image1Layer = [CALayer layer]; image1Layer.bounds = CGRectMake(0, 0 我将如何创建具有核心动画的图像序列.我想要:

添加image1 1秒钟然后删除图像

添加image2 2秒钟然后删除图像

添加image1 3秒钟然后删除

CGImageRef image1 = [self getimage1];    CALayer *image1Layer = [CALayer layer];    image1Layer.bounds = CGRectMake(0,480,320);    image1Layer.position = CGPointMake(0,0);    image1Layer.contents = (ID)image1;    CABasicAnimation *animation1 = [CABasicAnimation animationWithKeyPath:@"animation"];    animation1.repeatCount = 0;     animation1.duration = 2.0;    animation1.removedOnCompletion = YES; // i would like to remove image here    animation1.beginTime = AVCoreAnimationBeginTimeatZero;     [image1Layer addAnimation:animation1 forKey:nil];

上面的代码添加了一个图像但不删除它.

干杯

解决方法 最简单的方法是使用CABasicAnimation作为内容键:

CABasicAnimation *animation = [CABasicAnimation animation];animation.fromValue = (ID)[UIImage imagenamed:@"image1.png"].CGImage;animation.tovalue = (ID)[UIImage imagenamed:@"image2.png"].CGImage;animation.duration = 1.0f;animation.repeatCount = HUGE_VAL;//  animation.autoreverses = YES;[image1Layer addAnimation:animation forKey:@"contents"];

此动画将无限更改image1和image2之间的图层内容.您可能希望设置autoreverses属性以获得更平滑的过渡 – 以任何方式测试动画并选择您最喜欢的选项.

总结

以上是内存溢出为你收集整理的ios – 核心动画图像序列全部内容,希望文章能够帮你解决ios – 核心动画图像序列所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1060125.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-25
下一篇2022-05-25

发表评论

登录后才能评论

评论列表(0条)

    保存