究竟removeOnCompletion = NO究竟做了什么?

时间:2021-01-19 19:42:08

CAAnimation provides the removedOnCompletion property which defaults to YES.

CAAnimation提供removedOnCompletion属性,默认为YES。

Let's recognize these facts:

让我们认识到这些事实:

A) Core Animation only affects the Presentation Tree, but not the Model Tree. When an animation is done, you end up seeing whatever is set in the Model Tree. You can set a fillMode to kCAFillModeBoth for example, which will swap the value from the Presentation Tree over to the Model Tree once the animation is done. This causes your animation to not revert back (which is most likely what you want).

A)核心动画仅影响表示树,但不影响模型树。完成动画后,您最终会看到模型树中设置的内容。例如,您可以将fillMode设置为kCAFillModeBoth,一旦动画完成,它将把表示树中的值交换到模型树。这会导致您的动画无法恢复(这很可能是您想要的)。

B) I did an experiment. removedOnCompletion = NO will NOT have the same effect as kCAFillModeBoth or kCAFillModeForwards. To be more precise: It has absolutely no effect on how the result looks like when the animation is done. Wether it is "removed" or not, it seems to not affect the Presentation Tree at all.

B)我做了一个实验。 removedOnCompletion = NO与kCAFillModeBoth或kCAFillModeForwards的效果不同。更确切地说:完成动画时结果的效果绝对没有影响。它被“删除”与否,似乎根本不会影响表示树。

To explain what removedOnCompletion really does, the documentation is too weak in this regard. I don't get it. Can anyone explain what exactly would be removed, and what's the benefit of not having it removed?

为了解释removeOnCompletion真正做了什么,文档在这方面太弱了。我不明白。任何人都可以解释究竟会被删除的内容,以及没有删除它的好处是什么?

My guess is that Apple is talking about the animator object itself, which is added to the layer with -addAnimation:forKey: ... but again: What's the point of keeping it around?

我的猜测是Apple正在谈论动画师对象本身,它使用-addAnimation添加到图层:forKey:...但是又一次:保持它的重点是什么?

3 个解决方案

#1


12  

removedOnCompletion:

removedOnCompletion:

Basically, is the animation removed from the layer's actions when that animation is done.

基本上,当动画完成时,动画是从图层的动作中移除的。

YES - If you intend to use the animation only once, you do not need to use the delegate method to remove the animation from the layer upon completion.

是 - 如果您只想使用动画一次,则不需要使用委托方法在完成时从图层中删除动画。

fillMode:

在fillMode:

This property controls what happens visually when the animation is completed, depending on the type of fill mode specified.

此属性控制动画完成时视觉上发生的情况,具体取决于指定的填充模式类型。

#2


13  

If removedOnCompletion is YES, the animation will be removed on completion and there is nothing to "fill forward" at all. So if you want to use fillMode you must set removedOnCompletion to NO.

如果removedOnCompletion为YES,则动画将在完成时删除,并且根本没有任何“填充”。因此,如果要使用fillMode,则必须将removedOnCompletion设置为NO。

#3


0  

The presentation layer of the view is effected by the animation even it stopped. When remove the animation, the presentation layer will be revert to the value of model layer of the view, so you will get a result as an0 pointed.

即使它停止,视图的表示层也会受到动画的影响。删除动画时,表示层将恢复为视图模型层的值,因此您将得到一个指向的结果。

#1


12  

removedOnCompletion:

removedOnCompletion:

Basically, is the animation removed from the layer's actions when that animation is done.

基本上,当动画完成时,动画是从图层的动作中移除的。

YES - If you intend to use the animation only once, you do not need to use the delegate method to remove the animation from the layer upon completion.

是 - 如果您只想使用动画一次,则不需要使用委托方法在完成时从图层中删除动画。

fillMode:

在fillMode:

This property controls what happens visually when the animation is completed, depending on the type of fill mode specified.

此属性控制动画完成时视觉上发生的情况,具体取决于指定的填充模式类型。

#2


13  

If removedOnCompletion is YES, the animation will be removed on completion and there is nothing to "fill forward" at all. So if you want to use fillMode you must set removedOnCompletion to NO.

如果removedOnCompletion为YES,则动画将在完成时删除,并且根本没有任何“填充”。因此,如果要使用fillMode,则必须将removedOnCompletion设置为NO。

#3


0  

The presentation layer of the view is effected by the animation even it stopped. When remove the animation, the presentation layer will be revert to the value of model layer of the view, so you will get a result as an0 pointed.

即使它停止,视图的表示层也会受到动画的影响。删除动画时,表示层将恢复为视图模型层的值,因此您将得到一个指向的结果。