核心动画图像序列 [英] Core Animation Image sequence

查看:105
本文介绍了核心动画图像序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How would i go about creating an image sequence with core animation. I would like to:

添加image1 1秒然后删除图像

add image1 for 1 second then remove image

添加image2 2秒然后删除图像

add image2 for 2 seconds then remove image

将image1添加3秒然后删除

add image1 for 3 seconds then remove

    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];

以上代码会添加图片,但不会将其删除。

The above code adds an image but does not remove it.

干杯

推荐答案

最简单的方法是使用CABasicAnimation作为内容密钥:

The easiest way is to use CABasicAnimation for contents key:

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 属性以获得更平滑的过渡 - 以任何方式测试动画并选择您最喜欢的选项。

This animation will infinitely change the layer contents between image1 and image2. You may want to set autoreverses property for smoother transitions - test animation either ways and choose the option you like the best.

这篇关于核心动画图像序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆