How Animation Works
Something that I've noticed on the Cocoa and Quartz mail lists in questions about Core Animation is that many people are confused about what is happening to the 'real' object as the animation happens. When you use the simple Cocoa animator proxies (as outlined here) an animation is being created to do the animation. That animation is responsible for moving (or whatever) the stuff around that is being animated.
Where this becomes really important to understand is when you start to add your own custom animations. For example if you were to animate the change in the frameOrigin of a view with a custom animation, the view's current location and the location you set it to will be where the view starts from and ends at. Regardless of what the animation thinks it should be. The animation will interpolate between the fromValue and the toValue and all the intermediate values will be in that range. In other words, you have to be careful to have your animation start at the view's current location and have the animation end at the new location. If the view and animation's begin and end points don't match then you will see jumping and flashing in the animation.
The flashing happens because (at least this is what it looks like to me) the interpolated values go from (start time + delta) to (end time - delta). In other words the interpolation assumes that the initial value is good and the final value should be what you set it to with the set method. So if the fromValue is not the same as the initial value of the property the animation will jump in the 2nd frame from the initial value to the second frame's interpolated value. Then at the end of the animation it will jump from last frame - 1 to the final value.
Hopefully this will help someone trying to grok why they are seeing flashes and pops while using Core Animation.
[Updated] I changed this entry after further experimentation to clarify what is really happening.









Actually, fromValue is optional. If it isn't provided the current value in the presentation layer/ view is used.
Posted by Scott Anguish on November 24, 2007 at 12:32 AM MST #
Thanks for the comment Scott.
From what I've experienced, both the fromValue and toValue are optional. If you leave off the toValue from the animation it will animate to the value that you pass in the set method call.
Posted by Bill Dudney on November 24, 2007 at 04:37 AM MST #