05.01.2013 Views

Mac OS X Leopard - ARCAism

Mac OS X Leopard - ARCAism

Mac OS X Leopard - ARCAism

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

438<br />

CHAPTER 24 MAC <strong>OS</strong> X DEVELOPMENT: THE APPLICATION FRAMEWORKS<br />

Beauty<br />

NOTE For more on Safari, see Chapter 10. For more on Dashboard, see Chapter 3.<br />

As a platform, the <strong>Mac</strong> has always been known as the place to be for graphics. Whether or not<br />

that’s true, <strong>Mac</strong> <strong>OS</strong> X and its Aqua interface are certainly gorgeous. Applications on the <strong>Mac</strong><br />

inherit the system’s aesthetic brilliance for free, whether they are written in modern Cocoa, oldfashioned<br />

Carbon, or even a guest platform like Java.<br />

That’s because the application frameworks let developers build applications without worrying<br />

about any but the highest-level details of the graphics system. Little do they know that far<br />

below, OpenGL sits waiting for anyone who would dare traverse its sharp learning curve in the<br />

quest for pureness of power, flexibility, and performance.<br />

Luckily, between these two extremes lies Quartz, the graphics compositing engine. Quartz<br />

can be accessed via a series of graphics frameworks that provide expressiveness with images,<br />

animation, video, and drawing, while still maintaining a good dose of abstraction from the nittygritty<br />

details of OpenGL routines and primitives.<br />

When the free graphics from the application frameworks leave you feeling like you’ve gotten<br />

what you’ve paid for, it’s time to peek beneath the shiny skin of your Apple and examine the<br />

power that lies at its core.<br />

Core Animation<br />

If a computer interface is more like the real world, it’s more familiar, and therefore more usable.<br />

But computers are, in many ways, inherently alien to our everyday experiences. Contrast the<br />

instant on-off state change of a transistor to the slow opening and closing of a door.<br />

The obvious solution is to smooth the transitions between state changes using animation.<br />

While simple in theory, the difficulty in implementing animation has long forced developers to<br />

compromise between the ideals of user interface and the realities of a deadline.<br />

<strong>Leopard</strong>’s new Core Animation framework frees developers from this drudgery and introduces<br />

a lightweight layer-based design metaphor. By enabling and encouraging experimentation,<br />

Core Animation may well make <strong>Leopard</strong> the biggest revolution in human interface design since<br />

1984.<br />

Layers encapsulate drawing properties like color, border, opacity, and a completely customizable<br />

shadow. They also contain geometric properties like size and position, and the full<br />

range of affine transformations. Layers can contain images, stacks of Core Image filters (which<br />

we’ll get to in a moment), and an alpha mask. They can also be stacked and nested.<br />

What really sets a layer apart is what happens when you change a property. Rather than just<br />

reflecting the new state, the layer animates the transition. Multiple properties can be changed at<br />

the same time. For example, a layer could simultaneously shrink, slide, rotate, and fade.<br />

These animations are optimized to take advantage of hardware acceleration and other video<br />

card niceties, as well as being automatically threaded. Not only will the animation not block<br />

your main thread, but you can change a property while it is in the process of changing, and it will<br />

immediately be rerouted.<br />

The animation itself is also encapsulated as an object, so aside from being adjustable in the<br />

usual ways, such as duration, animations can be subclassed to provide for things like keyframes<br />

or following a Bézier path.<br />

As if all that weren’t enough, you can take advantage of Core Animation without even writing<br />

code. Views can be layer-backed, and many layer properties are accessible from within<br />

Interface Builder, as shown in Figure 24-16.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!