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.
Related
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.
I've seen this question asked here but it was never answered, and mines a bit different.
As an example: lets say I'm making a character that's constantly on a looping animation, and I have a button that you can hold down to make the character wear sunglasses, the sunglasses are kept on a separate animation of the same framerate and frame count. How can I use the button to switch them but start the new animation on the same frame as the last?
Edit: I've found a function for animators called PlayInFixedTime() this is the documentation for it, I don't know what it does but it mentions a "time offset" so it could be what I'm looking for, but I have no clue.
In my opinion you can solve this in 2 ways:
Animation Events: via script you are able to select the end of an animation even if it is looping
Wrap mode: there is an example here (https://answers.unity.com/questions/37080/stopping-an-animation-from-looping-at-the-end.html) but basically you are able to play an animation in Queue after the end of the previous. You can do it with a simple function so you are able to reuse it many times
Well, I want to make a animation application on iOS. So, I make an application using UIViews... But, it's very complicated. There are so many UIViews so I want to make it simple. So, There's any way to make an animation just using CGContext just one UIView? If someone knows PLS help.
You could use a timer that repeatedly fires so you call setNeedsDisplay every 0.01 second or something, and calculate every rectangle, circle, line, whatever to the right places at every time instant. You may well suffer some issues this way, though, since drawRect won't get called instantly every time, meaning you'll need to check the actual time when drawRect fires. You might even need to take the time it takes to execute your code into account.
Or just move the UIViews around in stead, using animateWithDuration:. I recommend that. No matter how complex your hierarchy is, doing it all in a single view will always be more complex.
I have a repeating animation that I need to synchronize with some other transient animations. The repeating animation is a scan line that moves across the screen for 4s. As it passes over images underneath, those images need to "blip."
The blipping images can come and go and move at the whim of the user. They are also not part of the same layer.
I can't figure out how to keep the scan line and the image animations in sync. I would consider adding them all to a CAAnimationGroup, but the "animations" property is a readonly NSArray, so it seems like I'd have to re-create the group every time one of the blipping animations is added, removed, or moves, which will be fairly often. I'm also guessing that creating a new group would mean the scan line animation would need to be restarted, causing it to be jerky.
According to this post:
=">CAAnimation that calls a method in periodic animation-progress intervals?
Core Animation is "time-based," but I'm not sure I fully understand what that means for a repeating animation and how reliable it is (I can't find this mentioned in any of the online documentation). Does that mean if I start the scan line repeating animation at time x, it will repeat at exact 4s intervals after it's been started? What about the app going to the background and returning or similar?
Thanks for your help!
Ryan
After fiddling with this for a bit, I found that I could synchronize my animations by making sure their beginTimes lined up. I started by setting the beginTime of the scan line animation:
scanAnimation.beginTime = CACurrentMediaTime();
From there I simply computed the offset within the 4s window (call it dt) and set the other animations' beginTimes to that:
blipAnimation.beginTime = scanAnimation.beginTime + dt;
This worked perfectly even if the beginTime was in the past; the animation engine actually extrapolated forward and animated the next blip dt seconds after the scan animation looped back.
The downside is that I've now absolutely bludgeoned the frame rate. I'm trying to find useful information about Core Animation performance, but so far to no avail. I've taken a pretty simple approach to laying out all of my images and animations so far and I'm prepared to rewrite a lot of code to optimize it, but I don't want to embark on a rewrite without some preparation. Any pointers to in-depth discussions about how Core Animation works would be really handy.
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.