我有 FrameChangeAnimation 类,它需要多个 Sprite 表和持续时间。所以假设我有 3 个 spritesheet,每个包含 16 个字符 block ,然后我给 '3' 秒作为持续时间。在将 FrameChangeAnimation 实例作为 CALayer 返回后,我将其附加到屏幕上,它可以流畅地播放 [16 帧/秒]
现在我想将此动画导出为视频。问题是,当我这次附加 CABasicAnimation 时,持续时间。 'Duration' 参数不起作用,所有帧都在一秒钟内播放。
GTAnimation *an = [[GTAnimation alloc] initWithFrame:CGRectMake(0, 0, videoSize.width, videoSize.height) withFileName"Host_Angry_" withSeconds:3.5];
CALayer *animationLayer = [CALayer layer];
animationLayer.bounds = CGRectMake(0, 0, videoSize.width, videoSize.height);
[animationLayer addSublayer:an.animLayer];
CABasicAnimation *fadeAnimation = [CABasicAnimation animationWithKeyPath"currentFrame"];
fadeAnimation.fromValue = [NSNumber numberWithFloat:1.0];
fadeAnimation.toValue = [NSNumber numberWithFloat:45.0];
fadeAnimation.additive = NO;
fadeAnimation.removedOnCompletion = NO;
fadeAnimation.beginTime = 0.0;
fadeAnimation.duration = 3.5;
fadeAnimation.repeatCount = HUGE_VAL;
fadeAnimation.fillMode = kCAFillModeBoth;
[an.animLayer addAnimation:fadeAnimation forKey"currentFrame"];
CALayer *parentLayer = [CALayer layer];
CALayer *videoLayer = [CALayer layer];
videoLayer.bounds = CGRectMake(0, 0, videoSize.width, videoSize.height);
[parentLayer addSublayer:videoLayer];
[parentLayer addSublayer:animationLayer];
videoLayer.anchorPoint = CGPointMake(0.5, 0.5);
videoLayer.position = CGPointMake(CGRectGetMidX(parentLayer.bounds), CGRectGetMidY(parentLayer.bounds));
animationLayer.anchorPoint = CGPointMake(0.5, 0.5);
animationLayer.position = CGPointMake(CGRectGetMidX(parentLayer.bounds), CGRectGetMidY(parentLayer.bounds));
videoComposition.animationTool = [AVVideoCompositionCoreAnimationTool videoCompositionCoreAnimationToolWithPostProcessingAsVideoLayer:videoLayer inLayer:parentLayer];
根据 AVVideoCompositionCoreAnimationTool 类的文档,
“任何动画都将在视频的时间线上进行解释,而不是实时的,因此您应该:
将动画的 beginTime 属性设置为 1e-100 而不是 0(CoreAnimation 将其替换为 CACurrentMediaTime);
关于ios - CFBasicAnimation 中带有自定义键的动画在导出视频时不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10448482/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (https://ogeek.cn/) | Powered by Discuz! X3.4 |