小编gam*_*r87的帖子

CoreAnimation - 不透明淡入淡出动画不起作用

我正在尝试创建一个相当简单的CoreAnimation用于AVComposition.我的目标是创建一个CALayer,通过各种子层,淡入淡出标题,然后淡出图像.幻灯片,基本上.这是使用导出到.mov AVAssetWriter.

在WWDC 2011 AVEditDemo的帮助下,我已经能够获得一个标题和图像.问题是它们同时都在屏幕上!

我创建了每个图层的不透明度为0.0.然后我添加了一个CABasicAnimation将它们从0.0淡化为1.0,使用以下代码:

CABasicAnimation *fadeInAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
fadeInAnimation.fromValue = [NSNumber numberWithFloat:0.0];
fadeInAnimation.toValue = [NSNumber numberWithFloat:1.0];
fadeInAnimation.additive = NO;
fadeInAnimation.removedOnCompletion = YES;
fadeInAnimation.beginTime = 1.0;
fadeInAnimation.duration = 1.0;
fadeInAnimation.fillMode = kCAFillModeForwards;
[titleLayer addAnimation:fadeInAnimation forKey:nil];
Run Code Online (Sandbox Code Playgroud)

问题似乎是'beginTime'属性."1.0"意味着延迟,因此它在动画开始后1秒开始.但是,它会立即出现在屏幕上.淡出动画

对于淡出,此代码的反向只是将fromValue更改为1.0,将toValue更改为0.0.它的开始时间为4.0,完美运行.

我正在使用以下内容来创建animatedTitleLayer:

CATextLayer *titleLayer = [CATextLayer layer];
titleLayer.string =self.album.title;
titleLayer.font = @"Helvetica";
titleLayer.fontSize = videoSize.height / 6;
titleLayer.alignmentMode = kCAAlignmentCenter;
titleLayer.bounds = CGRectMake(0, 0, videoSize.width, videoSize.height / 6);
titleLayer.foregroundColor = [[UIColor redColor]CGColor];
titleLayer.opacity …
Run Code Online (Sandbox Code Playgroud)

core-animation avfoundation calayer cakeyframeanimation ios

21
推荐指数
3
解决办法
3万
查看次数