我正在尝试在swift中创建一个视频编辑器。目前,我需要添加一个textlayer,我需要在其中从右向左导航文本。我用它的代码如下:
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)
现在,Text正在出现,但导航无效。请帮忙。提前致谢
答案 0 :(得分:0)
我使用以下动画方法解决了这个问题
let animation = CABasicAnimation(keyPath: "transform.translation.x")