Graphics Reference
In-Depth Information
When Should I Use Core Animation?
On certain online discussion forums, people often ask questions like, “I've heard this Core
Animation thing is something I should use, but I'm not sure when to use it and when to
just use standard views.” I would summarize the answer this way. Use views for user input
elements and use Core Animation for design elements. In some cases, however, it makes
sense to use a hybrid.
User Input
If you need to capture input from the user, use a standard control—which is based on
either an NSView on the Mac or a UIView on the iPhone. If you have design skills, Core
Animation layers can provide a simpler path to changing the look of your controls to suit
your design, but for the rest of us, leave the views alone. Your users will recognize them
and will know how to use them instinctively.
Design Elements
If your application requires some sort of animation to adorn the view, use Core
Animation layers. For example, if you want to rotate a sunburst image in the background
of your carnival game for the iPhone, use a Core Animation layer. Or if you want to
animate an image within your view, load the image and set the layer's contents field to
display the image. Then move its position with either implicit or explicit animation.
Hybrid
Sometimes, you want to adorn your control views with layers because this visually
enhances the view. For example, if you want to display an indeterminate progress
indicator in a view while some data is
downloading from a website, you can
design the view and place the progress
indicator in its center in Interface
Builder. Then you can make the contain-
ing view have a border and a rounded
rectangle by accessing the view's layer
and setting the cornerRadius and
borderWidth properties (see Figure 2-4).
FIGURE 2-4 Activity Indicator View with
Rounded Corners
What Shouldn't I Animate?
There are no hard and fast rules, so if you have gotten this far into this chapter and are
still uncertain what you should animate, you should review the principles we discussed so
far. These can guide your efforts.
After months of working closely with Core Animation and learning all the ins and outs,
however, it is clear that there are no absolute rules about what you should not animate.
You can make a case in favor of animating nearly anything. You should not make using
your interface difficult because of all the animation you add to it. For instance, don't
animate controls your user is going to need to click on or type text into. It's fine to
Search WWH ::




Custom Search