Graphics Reference
In-Depth Information
Filters
When used in conjunction with Core Image, Core Animation layers can have complex
filters applied to them by setting one or more of the filter fields. Core Image filters are
not, at the time of this writing, available on the iPhone.
Filter fields that you can animate include the following:
.
filters
The
filters
property is an array of filters that you can apply directly to the layer's
content. It affects the entire layer, including the border and background.
.
compositingFilter
Different from the
filters
property, the
compositingFilter
property uses a single
filter as its parameter.
.
backgroundFilters
The
backgroundFilters
property provides a way for you to apply filters to the
layer's background only.
Content
The content field of a layer is set using an image, specifically a
CGImageRef
. If you use a
CAKeyframeAnimation
to animate this field, you can create a simple slideshow application
with a minimal amount of code. You can create an array of
CGImageRef
objects and set
that array as your animation's
values
field. When the animation is added to the layer, it
transitions between each image in the order they are found in the array. You can alter the
order of the images by changing the order of the array. You can also change the type of
transition you use. We cover transitions in great depth in Chapter 6, “Layer Filters.”
Content fields that you can animate include
.
contents
The
contents
property expects a
CGImageRef
object to display an image.
.
contentsRect
Think of the
contentsRect
property as a view port of the layer contents. The
contents rectangle values (
x
,
y
, width, and height), are tied to the size of the layer
bounds. The four values of the
contentsRect
rectangle, however, are proportions
rather than actual points on the screen. The default is
0.0, 0.0, 1.0, 1.0
. When
you change the
x
, for example, the value is between 0.0 and 1.0. If you set
x
to 0.25,
the view port of the content's rect displays at pixel 100.0 of a 400.0-pixel wide layer
(400.0
0.25), or 25 percent of the layer's original width. If you set the width to
0.25, the width of the view port is be 100.0 pixels on a 400.0-pixel wide layer (400.0
×
×
0.25), or 25 percent of the layer's original width. Figures 2-1 and 2-2 demonstrate
how
contentsRect
works by showing what portion of the original image layer is
displayed in the
contentsRect
.