我有多个CATextLayers
正在添加到一个AVVideoComposition
。我想在视频中的特定时间点隐藏并显示它们。因此,我有以下代码:
CATransaction.begin()
CATransaction.setDisableActions(true)
let startVisible = CABasicAnimation(keyPath: "opacity")
startVisible.fromValue = 0.0
startVisible.toValue = 1.0
startVisible.beginTime = startTime
startVisible.duration = 0
startVisible.fillMode = .forwards
startVisible.isRemovedOnCompletion = false
textLayer.add(startVisible, forKey: "startAnimation")
CATransaction.commit()
CATransaction.begin()
CATransaction.setDisableActions(true)
let endVisible = CABasicAnimation(keyPath:"opacity")
endVisible.fromValue = 1.0
endVisible.toValue = 0.0
endVisible.beginTime = endTime
endVisible.duration = 0
endVisible.fillMode = .forwards
endVisible.isRemovedOnCompletion = false
textLayer.add(endVisible, forKey: "endAnimation")
CATransaction.commit()
这是可行的,但是,尽管CATransaction.setDisableActions(true)
,它确实会在不透明度级别之间设置淡入淡出动画。我怎样才能改变这一点,使不透明度的变化是即时的,而不是动画?
1条答案
按热度按时间gmxoilav1#
我找到的解决方案是将持续时间设置为很小的量。001,而不是0。不需要
CATransaction
函数。