Graphics Reference
In-Depth Information
FIGURE 6-1
Gaussian Blur Filter Applied to Image
Animating an Applied Filter
You likely want to apply a filter to a layer in response to user input. For example, you
might want to create a Core Animation layer-based button that has a 5-pixel Gaussian
blur applied to it when clicked. To do so, create a layer-backed
NSView
derived view to
contain the layer that will be animated. When you add the filter to the layer in your view
initialization, set its
inputRadius
field with an initial value of 0.0 so that no evidence of
the effect is visible when the layer first displays. Then, in response to a click, you can
animate the
inputRadius
property to a value that makes the button blur and return to
clear. On the companion website, the demo application Click to Blur demonstrates this
capability. Open that project now to see this capability in action.
Each image you see in Figure 6-2 represents one view; each view contains a Core
Animation layer. The image you see is the contents of the view's layer. Behind each layer
is a view called BlurView that does the following:
.
Holds the
CALayer
-derived layer, called
BlurLayer
, upon which the animation gets
performed
.
Receives the mouse-down event we use to trigger the animation
Every layer has a
filters
field that holds an
NSArray
of Core Image filter objects. Think
of this array as an array of filters that might or might not be used. You can build up a list
of filters that you might use, and then you can enable them through key-value coding
when you receive user input, such as a button click. We get to the key-value coding in a
moment. The Click to Blur demo application causes the icon image to blur and become
clear again when the view receives a mouse click.