我正在尝试让calayer在视频出现时暂停该视频。我不知道如何将其添加为另一个calayer或动画。这是我在导出之前添加calayer时的代码。因此,当动画发生时,我希望视频在出现时暂停,然后在动画停止后恢复。
let titleLayer = CATextLayer()
titleLayer.backgroundColor = NSColor.clearColor().CGColor
titleLayer.string = "Dummy text"
titleLayer.font = NSFont(name: "Helvetica", size: 28)
titleLayer.shadowOpacity = 0.5
titleLayer.alignmentMode = kCAAlignmentCenter
titleLayer.frame = CGRectMake(0, 50, size.width, size.height / 6)
let animation: CABasicAnimation = CABasicAnimation(keyPath: "opacity")
animation.duration = 0
animation.fromValue = Int(1.0)
animation.toValue = Int(0.0)
animation.beginTime = 5
animation.removedOnCompletion = false
animation.fillMode = kCAFillModeForwards
titleLayer.addAnimation(animation, forKey: "animateOpacity")
答案 0 :(得分:1)
您可以在将动画添加到图层之前暂停视频,然后在动画结束时恢复该视频。要知道动画何时结束,您可以让对象成为animation
的委托,然后在animationDidStop:finished:
委托方法中恢复播放。
func showTitle() {
// configure animation { .. }
animation.delegate = self
// pause video
titleLayer.addAnimation(animation, forKey: "animateOpacity")
}
func animationDidStop(anim: CAAnimation, finished flag: Bool) {
// play video
}