我正在尝试用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")
关于swift - 如何快速将左右动画添加到文本图层,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40402184/