tl;dr 在 animationDidStop:finished: 委托回调中显式调用 setNeedsDisplay。
根据 Lucas Tizma 的帖子(参见上面的编辑 2),我尝试手动删除动画。我选择了一种比他基于块的方法更简单的方法,方法是将图层设置为在它们上设置的动画的代表。这样,动画开始和停止回调直接到达相关层。好吧,在 animationDidStop:finished: 回调中明确删除动画并不能解决问题。例如,有时(请参阅下面的日志,尤其是时间戳)动画会停止并检查它是否已被删除,这表明它已被删除,但是使用实际模型值的准确绘制发生在很久以后。
// animationDidStop:finished: call back code
NSLog(@"layer animation stopped");
// check if any animations exist
NSLog(@"animation keys: %@", [self animationKeys]);
// remove animations and check
NSLog(@"removing animations");
[self removeAllAnimations];
NSLog(@"animation keys: %@", [self animationKeys]);
// log
2012-10-11 11:47:16.774 ASPathAnimationTest[3017:c07] on presentation layer 1
2012-10-11 11:47:16.774 ASPathAnimationTest[3017:c07] 335 animation draw update, animator is 0.982606
2012-10-11 11:47:16.775 ASPathAnimationTest[3017:c07] startPoint: {100, 90} - endPoint: {100, 100} - newPoint: {100, 99.8261}
<snip>
2012-10-11 11:47:16.791 ASPathAnimationTest[3017:c07] startPoint: {1000, 50} - endPoint: {1000, 100} - newPoint: {1000, 99.1303}
2012-10-11 11:47:16.792 ASPathAnimationTest[3017:c07] layer animation stopped
2012-10-11 11:47:16.792 ASPathAnimationTest[3017:c07] animation keys: (null)
2012-10-11 11:47:16.793 ASPathAnimationTest[3017:c07] removing animations
2012-10-11 11:47:16.793 ASPathAnimationTest[3017:c07] animation keys: (null)
2012-10-11 11:47:16.794 ASPathAnimationTest[3017:c07] layer animation stopped
2012-10-11 11:47:16.794 ASPathAnimationTest[3017:c07] animation keys: (null)
2012-10-11 11:47:16.794 ASPathAnimationTest[3017:c07] removing animations
2012-10-11 11:47:16.795 ASPathAnimationTest[3017:c07] animation keys: (null)
2012-10-11 11:47:16.795 ASPathAnimationTest[3017:c07] layer animation stopped
2012-10-11 11:47:16.819 ASPathAnimationTest[3017:c07] animation keys: (null)
2012-10-11 11:47:16.820 ASPathAnimationTest[3017:c07] removing animations
2012-10-11 11:47:16.820 ASPathAnimationTest[3017:c07] animation keys: (null)
2012-10-11 11:47:16.821 ASPathAnimationTest[3017:c07] layer animation stopped
2012-10-11 11:47:16.821 ASPathAnimationTest[3017:c07] animation keys: (null)
2012-10-11 11:47:16.821 ASPathAnimationTest[3017:c07] removing animations
2012-10-11 11:47:16.822 ASPathAnimationTest[3017:c07] animation keys: (null)
2012-10-11 11:47:16.822 ASPathAnimationTest[3017:c07] layer animation stopped
2012-10-11 11:47:16.822 ASPathAnimationTest[3017:c07] animation keys: (null)
2012-10-11 11:47:16.823 ASPathAnimationTest[3017:c07] removing animations
2012-10-11 11:47:16.823 ASPathAnimationTest[3017:c07] animation keys: (null)
2012-10-11 11:48:00.000 ASPathAnimationTest[3017:c07] on presentation layer 0
2012-10-11 11:48:00.000 ASPathAnimationTest[3017:c07] 336 animation draw update, animator is 1.000000
<snip, there are 5 lines so draw and point logs go here>
2012-10-11 11:48:00.021 ASPathAnimationTest[3017:c07] 340 animation draw update, animator is 1.000000
2012-10-11 11:48:00.023 ASPathAnimationTest[3017:c07] startPoint: {100, 90} - endPoint: {100, 100} - newPoint: {100, 100}
<snip>
2012-10-11 11:48:00.026 ASPathAnimationTest[3017:c07] startPoint: {1000, 50} - endPoint: {1000, 100} - newPoint: {1000, 100}
在查看日志并注意到动画确实被删除的事实后,只是使用实际准确的模型值重新绘制有时直到几秒钟甚至几分钟后才会发生,我更改了 animationDidStop:finished: 委托回调以显式调用图层上的 setNeedsDisplay。答对了。