我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 - CABasicAnimationanimationDidStart确实被调用,但animationDidStop从未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33400206/