By Jeff LaMarche on December 22, 2010
Core Animation is awesome. It makes doing a lot of complex, fancy animations downright easy. One of the really nice built-in features of Core Animation is the ability to use animation curves. These curves let you specify whether the animation happens linearly (at the same pace throughout the animation), or whether the animation eases in, eases out, or does both.
When you have to go closer to the metal and use OpenGL ES, you’re not so lucky. We don’t have animation curves provided for us in OpenGL ES. We have to interpolate ourselves. Fortunately, the math behind animation curves is straightforward. Plus, there are far more curves than just the four Apple offers.
I haven’t run across a good library for generating animation curves, so I’ve decided to release my animation curve functions as public domain (no attribute required, no rights reserved). Here is a graph of all the different animation curves I’m releasing:
Here is the original Numbers.app document that generated the graph, and here is the Xcode project that generated the data. The project also contains all the functions needed to plot these curves.
Apple doesn’t document which calculations they use for easing, but my guess is that they’re quadratic. I’m not sure, though, since many of the curves yield similar results.
All of the interpolation functions included in the Xcode project above take three inputs and return a GLfloat containing the interpolated value. The first parameter, t, is the percent of the way through the animation you want a value calculated for. This is a clamped float that should be in the range 0.0 to 1.0. Values above 1.0 will be treated as 1.0 and values below 0.0 are treated as 0.0. The second parameter, start, is the value when the animation starts. The third parameter, end, is the final value to be animated toward.
If you want to apply a curve to a CGPoint or Vector3D, you have to call the function multiple times for each component (x/y or x/y/z).
Here are the functions included in the project above:
By Jesper on September 16, 2010
Some of you might know that text rendered by a layer-backed NSTextField label (so, with Core Animation) on Mac OS X onto an alpha-transparent background (a layer with no direct opaque background, regardless of what that background may be, within the same layer) is drawn in a very peculiar way, a way which I will charitably characterize as “shitty”.
By Matt Long on October 21, 2009
Our Core Animation book should be available by the end of the year. Go ahead and pre-order it now at Amazon if you would like . When we started writing for Addison-Wesley back in September of 2008, I had no idea how long to expect it to take to finish a technical book as this was my first. One thing I discovered though, is that it is when you are about ready to go to production you start to realize all of the things that you probably should have added to the book, but didn’t think of in time. This blog post will cover one such item as a way to make up for not thinking of it in time. I may include this in a second edition if there is one, but consider this one a freebie.
By adamwulf on October 16, 2009
I'm looking to perform a perspective transform on a UIView (such as seen in coverflow). you'll need to work with the UIView's layer, using a CATransform3D to perform the layer's rotation.