核心动画图像序列

use*_*443 4 iphone core-animation image ios

我将如何创建具有核心动画的图像序列.我想要:

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

添加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];
Run Code Online (Sandbox Code Playgroud)

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

干杯

Vla*_*mir 9

最简单的方法是使用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"];
Run Code Online (Sandbox Code Playgroud)

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