Graphics Reference
In-Depth Information
Your Free Lunch
They say that there is no such thing as a free lunch, but when it comes to animating
with Core Animation, you don't just get lunch, you get a drink and desert as well. For
example, all the drawing going on is happening behind the scenes using OpenGL. Yet,
you don't need to know anything about OpenGL to take advantage of the hardware accel-
eration offered by your video card. This is fully abstracted by Core Animation. If you do
want to get to the more nuts-and-bolts level of OpenGL, though, you can do so by using
the CAOpenGLLayer on OS X. As of this writing, things aren't quite as easy on the iPhone
for OpenGL, but they are not too far off. The layers and layer-backed views on the iPhone
also give you great performance benefits.
Another freebie in Core Animation is that all the animation happens on a background
thread. This means that the user interface isn't blocked when the animation runs. And
you don't need to be a multithreading
expert to take advantage of it! In fact, if
you've never worked with multiple
threads, you won't notice a thing. Just
set the animatable property on your
layer or view and watch the action
happen.
NOTE
To learn more about how to use Core
Animation in your iPhone apps, see Chapter
13, “Core Animation on the iPhone.”
What Is a Layer?
The layer, represented by the CALayer class and its derivatives, is the most basic funda-
mental building block you will use for your all your Core Animation-based applications.
All Core Animation layers provide a lightweight layer within a view that enables you to
display visual content. Here is how Apple describes a CALayer in the API documentation: 1
CALayer is the model class for layer-tree objects. It encapsulates the position, size,
and transform of a layer, which defines its coordinate system. It also encapsulates
the duration and pacing of a layer and its animations by adopting the
CAMediaTiming protocol, which defines a layer's time space.
Notice how it says that it is the “model class.” This might be confusing if you are familiar
with the Model-View-Controller (MVC) design pattern, as you might more naturally think
that because Core Animation is of a visual nature, the View part of MVC might make
more sense. Ultimately, it is the NSView on the OS X side and the UIView on the iPhone
side in which the layer is stored that does the drawing. The CALayer simply contains the
data (model) that is relevant to all the layer's attributes such as background color, border
width, position, size, transform, and such.
1 From p. 7 of Apple's CALayer Class Reference: http://developer.apple.com/mac/library/
documentation/GraphicsImaging/Reference/CALayer_class/CALayer_class.pdf.
 
 
Search WWH ::




Custom Search