我正在使用AVMutableComposition制作视频。我需要在不同的时间间隔添加文本覆盖。即。
1.显示字符串“abc”从0秒到2秒后隐藏
1.显示字符串“xyz”从1秒到1.5秒后隐藏
1.显示字符串“qwe”从2秒到5秒
我正在使用下面的代码添加文本覆盖,但它的静态和通过视频停留。
let parentLayer = CALayer()
parentLayer.frame = CGRect(x: 0, y: 0, width: size.width, height: size.height)
let videoLayer = CALayer()
videoLayer.frame = CGRect(x: 0, y: 0, width: size.width, height: size.height)
let subtitleText = CATextLayer()
subtitleText.font = font
subtitleText.frame = CGRect(x: 0, y: 100, width: size.width, height: 50)
subtitleText.string = "hhh"
subtitleText.alignmentMode = kCAAlignmentCenter
subtitleText.foregroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1).cgColor
subtitleText.displayIfNeeded()
parentLayer.addSublayer(videoLayer)
parentLayer.addSublayer(subtitleText)
任何帮助是高度赞赏。
2条答案
按热度按时间b5buobof1#
如果有人需要这个问题的答案,很抱歉我找不到一个直接的解决方案,所以我做了一个昂贵的工作。
6mzjoqzu2#
在CALayer上使用CABasicAnimation,指定AVMutableComposition的呈现时间范围:
要显示CATextLayer从 1.5 秒到 3.0 秒,请用途: