gpt4 book ai didi

ios - 核心动画图像序列

转载 作者:可可西里 更新时间:2023-11-01 05:10:55 25 4
gpt4 key购买 nike

我将如何着手创建具有核心动画的图像序列。我愿意:

添加 image1 1 秒然后移除 image

添加 image2 2 秒然后删除图像

添加image1 3秒然后移除

    CGImageRef image1 = [self getImage1];
CALayer *image1Layer = [CALayer layer];
image1Layer.bounds = CGRectMake(0, 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 - 核心动画图像序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3958952/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com