How to add multiple CALayer to a video file using

2019-05-10 21:34发布

I want to add multiple CALayer one after another by time sequence.I can add one layer to video file using this link Here. Now my question is that how can i add multiple CALayer to video file.

Thanks in advance..

1条回答
成全新的幸福
2楼-- · 2019-05-10 22:19

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!

查看更多
登录 后发表回答