ios - 核心动画图像序列

标签 ios iphone image core-animation

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

添加 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/

相关文章:

ios - 如何在 ios 中的特定 textView 文本上创建超链接

ios - 哪些传感器可以在 iPhone 后台运行?

ios - 如何将委托(delegate)设置为 QLPreviewController 的 UIActivityViewController?

c# - 在 C# 中缩放图像的好方法是什么?

ios - 传递的 NSManagedObject 实例变成错误 - RKManagedObjectStore

ios - 以毫秒为单位转换 DateTime iOS

ios - Swift - 将初始数据从 mysql 加载到 uidatepicker(不是从简单的 uipiker)

iphone - 有没有办法使用命令行创建新的 XCode 项目?

python - 如何使用python删除图像中人物周围的白色边框/边缘?

image - 如何调用magento产品 View 中的图像?