我saw一个lot的 answers关于这个topic ,但无法解决我的特殊情况。
Here is a video with complete animation and logging timeline
class AnimationDelegate: UIView {
deinit {
print("AnimationDelegate deinitialized")
}
override func animationDidStart(anim: CAAnimation) {
print("animationDidStart")
}
override func animationDidStop(anim: CAAnimation, finished flag: Bool) {
print("animationDidStop")
}
func play() {
let line_1 = CAShapeLayer()
...
let animation = CABasicAnimation()
animation.delegate = self
animation.duration = 3000
animation.repeatCount = 1
animation.keyPath = "strokeEnd"
animation.fromValue = 0
animation.toValue = 360
layer.addSublayer(line_1)
line_1.addAnimation(animation, forKey: "StrokeAnimation")
}
}
let delegate = AnimationDelegate(frame: container.bounds)
container.addSubview(delegate)
delegate.play()
问题是 animationDidStart 被调用了,但是 animationDidStop 没有被调用。
这怎么可能?
最佳答案
animationDidStop 将被调用,如果您等待更长时间。但这肯定不是您预期的行为。
我了解到您想让动画运行 3 秒而不是 3000 秒;一旦完成,就会收到来自委托(delegate)回调的通知,即 animationDidStop。
因此,您需要更改:
animation.duration = 3
和:
animation.toValue = 1
因此,您会看到 animationDidStart 和 animationDidStop 都将相应地被调用。
关于ios - CABasicAnimation animationDidStart 确实被调用了,但是 animationDidStop 从来没有被调用过,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33400206/