Bli*_*lip 4 animation ios swift
标签栏中心的白色圆圈通过反复淡入淡出而脉动。这是执行脉动动画的代码:
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)
Run Code Online (Sandbox Code Playgroud)
问题是,当标签栏消失时,例如,隐藏在另一个视图后面,或者当我单击主页按钮并再次返回应用程序时,动画停止,白色圆圈消失,如下所示:

我希望它继续动画,因为我设置.repeat为options. 有什么帮助吗?
我通过更换解决我的问题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")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
677 次 |
| 最近记录: |