What exactly does removedOnCompletion = NO do? - iphone

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?

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:
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.

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.

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.

Related

Unity animation transition glitches back to last animation

So, I have my animation and it goes to an empty state.
The thought behind this is that it goes to it's default no animation state.
However, before it does that, it glitches back in to the old animation.
I tested it, it only happens whenever I go from an animation to an empty state.
It always glitches for the same amount of time for each transition, however it is different for each transition.
I have never seen something like this before, does anyone of you know the problem?
The animation
The clear state
The transition
What do you mean by glitching? I am going to take a guess and say you do not want an exit timer, so uncheck this box.
An exit timer is just used to transition between two states and will take the amount of time to wait to transition. In your transition block, it also shows you stacking your two animations which might be why everything looks weird for a short time. Instead of an exit timer, you might want to use parameters to change your states or directly set them in code.
The other possible issue is the checkbox Write Defaults.
From the Unity Docs, the description of Write Defaults is
Whether or not the AnimatorStates writes back the default values for
properties that are not animated by its Motion.
Unexpected behavior with animators can be caused by Write Defaults if you are not familiar with how they work or what they do. Again, it is hard to say what exactly is wrong with the description of your issue. Try unchecking each of these boxes individually and seeing if either one fixes your issue. If that does not work, try both and if that does not work, let me know what your issue is in more detail. Possibly attach a gif or video showing what is breaking as the written description is not helping too much.

Avatar removed from Pivot point

I was animating an avatar, and was trying various things out, and all of a sudden she was transformed from her pivot point. She also lost the T-pose. I couldn't figure out how to get her back to the original state, removing the animation didn't help. I am going to deleting that avatar and start over, but first I want to learn from this.
I am really looking for a few things here:
how could that happen? It looks like somehow the state at some point of the animation became the new "ground" state or something.
is there anyway I could inspect this state, edit it, or failing that, reset it?
is there something I should read somewhere to understand this better? I found nothing
Screen shot of displaced avatar:
The top level inspector in the heirarchy:
Here is one with the animator controller:
Update:
The key was the suggestion by Fiffe that you need to make sure your flow gets to your exit state. In my case I was neglecting to do that.
There's few things that might be causing this. You probably wanna play around with animation clip settings - you can find them by selecting animation clip.
You can read more about it here https://docs.unity3d.com/Manual/class-AnimationClip.html
You probably want to turn off Apply Root Motion in your Animator too.
If that doesn't help you should check if you don't have any empty states (without animations) in your animator controller.

Access interim points while UIView is animated

I'm animating an image in an UIImageView. This works just great with Core Animation. Now I want to attach one end of a line permanentely to the center of this UIIMageView. But with Core Animation I only get the starting point and the end point of the UIImageView. Is there a possibility to access interim points during the animation? I want to extend the functionality to many UIImageViews, which are animated, with a line attached to them. I don't want to create timers to monitor all animations and calculate my own interim points. Does somebody have any suggestions? Thanks!
Bye, Björn
If you're using Core Animation (I'm not sure if this works with strictly UIView-based animation), you should be able to get a particular instantaneous value of your property by looking at the presentationLayer property of your view's backing CALayer. That property exposes a read-only copy of the current set of values as a layer is animating. You can look at this on a display link "timer" and update something else, etc.
I'm having a tough time picturing exactly what you're trying to accomplish overall, but this might get you started.
I found this post, which points to the right direction: http://dbachrach.com/blog/2008/04/instantaneous-frame-of-moving-core-animation-views/
But there's still one problem: this seems to work for CABasicAnimations only, not for the standard animations. Is there a way to access interim points when using standard animations ([UIView beginAnimation] ...)?? Thanks.
Björn

How can we get kCAOnOrderOut to work?

The Apple documentation claims that the Core Animation action key kCAOnOrderOut has one sole purpose: to animate a layer out of sight when it either becomes hidden or has -removeFromSuperlayer called on it. I'm only referring to the latter case in this question.
In practice, when -removeFromSuperlayer is called, the layer is removed immediately, and no animation is performed on it.
It's been hinted at that this is a difference between the Presentation and Model layers, but I'm not experienced enough in Core Animation to know what to make of this.
If anyone can explain how to force the animation to run before the layer is removed, when the animation is returned for the key kCAOnOrderOut, it would be appreciated by at least me and a few other people.
Thanks.
I have no idea how to implement it with the key kCAOnOrderOut, but I ran into a similar problem a while back. My fix was to set the animation with a specific duration and immediately send off a delayed timer that waited the same amount of time as the animation duration. After my timer fired I would remove the layer/view.

Unable to see second animation started from separate animationDidStop

I'm having some problems getting CoreAnimation to perform multiple animations in succession on the iPhone simulator. I have many layers in my application that I animate – these layers are all sublayers of the layer associated with a UIView in my application. After I animate the first sublayer's position (using explicit animation - CAKeyFrameAnimation), I do the following in the animationDidStop delegate method:
I remove the layer from its superlayer
I start a CATransaction to animate 2 other sublayers' positions simultaneously - these layers are also animated explicitly with individual CAKeyframeAnimations added to the respective layers.
I then reuse the 1st layer with different contents and add that back to the superlayer in a separate position (intentionally not animated).
When I run my application, I see the first animation occur, the layer then gets removed, and the layer gets added back with new contents in the new position, but I never see the animation of the 2 layers in step 2. Interestingly, I do get animationDidStop calls for each of the 2 layers animating in the transaction. Since I get these calls it would appear the animations are occurring, but the animations do not appear on screen. I also tried removing the transaction in case I didn't have that set up correctly and am seeing the same results.
Is it possible to link together multiple animations in this manner?
Any insights or suggestions are greatly appreciated. Thanks in advance for your help.
My first guess would be that you are adding your animation in the animationDidStop to a layer that is no longer valid. Of course, I can't know that unless you post some code.
Second, you should take a look at the timing documentation for Core Animation as the way you're doing it, while functional, may not be the best way. Specifically take a look at this section:
The timing protocol provides the means
of starting an animation a certain
number of seconds into its duration
using two properties: beginTime and
timeOffset. The beginTime specifies
the number of seconds into the
duration the animation should start
and is scaled to the timespace of the
animation's layer. The timeOffset
specifies an additional offset, but is
stated in the local active time. Both
values are combined to determine the
final starting offset.