Proud Member
Proud Member

Reputation: 40496

What exactly does removedOnCompletion = NO do?

CAAnimation provides the removedOnCompletion property which defaults to 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).

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.

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?

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?

Upvotes: 14

Views: 6862

Answers (4)

DrMickeyLauer
DrMickeyLauer

Reputation: 4674

removedOnCompletion = YES really is just a shortcut. In most cases I'd discourage using it, but rather set the model values as well.

Animations that linger around although you don't make use of them may consume energy and bandwidth and mess your logic up, since you can no longer inspect animationKeys to poll (should you ever need that) whether they're already finished.

Upvotes: 0

Danyun Liu
Danyun Liu

Reputation: 3092

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.

Upvotes: 0

an0
an0

Reputation: 17530

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.

Upvotes: 14

Evan Mulawski
Evan Mulawski

Reputation: 55334

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:

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

Upvotes: 13

Related Questions