标签栏中心的白色圆圈通过反复淡入和淡出而脉动。这是执行脉动动画的代码:
UIView.animateKeyframes(withDuration: 1.4, delay: 0, options: [.repeat, .autoreverse], animations: {
UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 0.7, animations: {
self.recordingPulsatingCircleView?.alpha = 1
})
UIView.addKeyframe(withRelativeStartTime: 0.7, relativeDuration: 1.4, animations: {
self.recordingPulsatingCircleView?.alpha = 0
})
}, completion: nil)
问题是,当标签栏消失(例如,被隐藏在另一个视图后面)时,或者当我单击“主页”按钮并再次带回应用程序时,动画停止,并且白色圆圈消失了,就像这样:
我希望它会继续制作动画,因为我将.repeat
设置为options
之一。有帮助吗?
答案 0 :(得分:1)
我解决了问题,方法是将UIView.animateKeyframes
替换为CABasicAnimation
,然后将isRemovedOnCompletion
的属性CABasicAnimation
设置为false
。这样,当视图放置在屏幕外时,动画不再停止。这是代码:
let animation = CABasicAnimation(keyPath: "opacity")
animation.fromValue = 0
animation.toValue = 1
animation.duration = 0.7
animation.autoreverses = true
animation.repeatCount = .infinity
animation.isRemovedOnCompletion = false //Set this property to false.
recordingPulsatingCircleView?.layer.add(animation, forKey: "pulsating")
答案 1 :(得分:0)