How to add multiple CALayer to a video file using AVMutableComposition and CALayers on iOS

青春壹個敷衍的年華 提交于 2019-12-05 21:51:43

Most straightforward way is to bundle several layers into single layers. You will have to add instructions to add it at some point and remove when not needed. Something like this:

CABasicAnimation *fadeAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
fadeAnimation.fromValue = [NSNumber numberWithFloat:(float)!fadeIsIn];
fadeAnimation.toValue = [NSNumber numberWithFloat:(float)fadeIsIn];
fadeAnimation.additive = NO;
fadeAnimation.removedOnCompletion = NO;
fadeAnimation.beginTime = atTime;
fadeAnimation.duration = duration;
fadeAnimation.fillMode = kCAFillModeBoth;
[layer addAnimation:fadeAnimation forKey:nil];

In this example you can do fade In/Outs (1.0 start and 0.0 is basically fadeout). atTime is time where you want this layer to be start displaying/removing and duration is fade duration (so if some small number 0.0001 (never tried 0.0 (why?)), it will do no fade but just plain cut). layer is CALayer that you want to be displayed/removed at some point. You need to call this method twice obviously, once for fade in, second for out. Let me know if you have better solution! :) ps just notices this is a really old question!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!