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
不是。
这怎么可能?