gpt4 book ai didi

ios - 在特定时间向视频添加文本层

转载 作者:行者123 更新时间:2023-12-01 15:48:08 24 4
gpt4 key购买 nike

我想为视频的最后 4 秒添加一个文本层。这是我到目前为止所拥有的:

// 1 - Set up the watermark text layer
CATextLayer *waterMarkText = [[CATextLayer alloc] init];
[waterMarkText setFont:@"Helvetica-Neue"];
[waterMarkText setFontSize:30];
[waterMarkText setFrame:CGRectMake(0, 0, self.size.width, 80)];
[waterMarkText setString:@"made with Videofy"];
[waterMarkText setAlignmentMode:kCAAlignmentRight];
[waterMarkText setForegroundColor:[[UIColor whiteColor] CGColor]];

//Fade In the watermark
CABasicAnimation *fadeInAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];

fadeInAnimation.duration = 2;
fadeInAnimation.fromValue = [NSNumber numberWithFloat:0.0];
fadeInAnimation.toValue = [NSNumber numberWithFloat:1.0];
fadeInAnimation.beginTime = videoDuration - 4;
fadeInAnimation.removedOnCompletion = NO;
[overlayLayer addAnimation:fadeInAnimation forKey:@"animateOpacity"];

动画添加到最终视频中,但水印从视频开头可见。如何在动画开始前将不透明度设置为 0?

(我尝试将 watermarkText 的不透明度设置为 0,但这似乎覆盖了动画。)

最佳答案

因此,为了使出现和消失起作用,您需要添加两个动画 - 每个动画一个。这是一个适用于我的示例代码。在这种特殊情况下,我从视频的 0 到 1 秒添加了一个文本层。您应该为动画的开始时间设置自己的值。您应该在开始时将不透明度设置为 0。

        textLayer.opacity = 0

let startVisible = CABasicAnimation(keyPath: "opacity")
startVisible.duration = 0.1 // for appearing in duration
startVisible.repeatCount = 1
startVisible.fromValue = 0.0
startVisible.toValue = 1.0
startVisible.beginTime = 0.0 // overlay time range start second
startVisible.isRemovedOnCompletion = false
startVisible.fillMode = CAMediaTimingFillMode.forwards
textLayer.add(startVisible, forKey: "startAnimation")

let endVisible = CABasicAnimation(keyPath: "opacity")
endVisible.duration = 0.1 // for disappearing in duration
endVisible.repeatCount = 1
endVisible.fromValue = 1.0
endVisible.toValue = 0.0
endVisible.beginTime = 1.0 // overlay time range end second
endVisible.fillMode = CAMediaTimingFillMode.forwards
endVisible.isRemovedOnCompletion = false
textLayer.add(endVisible, forKey: "endAnimation")

关于ios - 在特定时间向视频添加文本层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26802038/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com