如何在swift中添加从左到右的动画到文本层



我试图在swift创建一个视频编辑器。目前,我需要添加一个文本层,我需要从右到左导航文本。我使用的代码如下

let textLayer = CATextLayer()
textLayer.backgroundColor = UIColor.clearColor().CGColor
textLayer.foregroundColor = UIColor.whiteColor().CGColor
textLayer.string = "T E S T"
textLayer.font = UIFont(name: "Helvetica", size: 28)
textLayer.shadowOpacity = 0.5
textLayer.alignmentMode = kCAAlignmentCenter
textLayer.frame = CGRectMake(0, 50, showInBounds.width,showInBounds.height/6)
textLayer.shouldRasterize = true
let parentLayer = CALayer()
let videoLayer = CALayer()
parentLayer.frame = CGRectMake(0, 0, showInBounds.width, showInBounds.height);
videoLayer.frame = CGRectMake(0, 0, showInBounds.width,  showInBounds.height);
parentLayer.addSublayer(videoLayer)
parentLayer.addSublayer(textLayer)
mainComposition.animationTool = AVVideoCompositionCoreAnimationTool(postProcessingAsVideoLayer: videoLayer, inLayer: parentLayer)
return (mixComposition, mainComposition)

现在,文字出现,但导航不工作。请帮助。提前感谢

我已经用下面的动画方法解决了这个问题

let animation = CABasicAnimation(keyPath: "transform.translation.x")

最新更新