Graphics Reference
In-Depth Information
FIGURE 6-2
Gaussian Blur Filter Applied to Image
Key-value coding manipulates the values of the filter, but to do so we first need to name
each filter we plan to use. The name of the filter is important because it will be used in
the key-path to the filter parameters such as inputRadius . For further discussion, take a
look at the sidebar, “Key-Paths in Key-Value Coding.” We also need to change the initial
input radius (the inputRadius parameter on the CIFilter object) value to 0.0f . This is
the starting value for the input radius of the blur. We start at zero, so the blur effect is not
initially visible.
Key-Paths in Key-Value Coding
Key-Value Coding (KVC) is a useful feature of the Objective-C language. If you have had any
experience writing code in Objective-C, you are likely already familiar with the concept. KVC
enables member or instance variables (commonly referred to as ivars ) of an Objective-C class
to be accessed by name rather than by direct reference by using a call to -setValue:forKey
and -valueForKey to set and retrieve values for your ivars. KVC is what enables bindings
to work.
Key-paths are important to understand. In this chapter, we demonstrate an example of using
KVC to bind filter parameters to Cocoa controls such as NSSlider s. When the user slides
the slider in the app, the slider looks up the object it is bound to and then attempts to
access the ivar variable specified in the key-path. Say we have a Core Animation layer object
in our AppDelegate class called blurLayer to which we have added a Gaussian blur
CIFilter object named blur . To access this filter's inputRadius value, the key-path we use
in an NSSlider control is blurLayer.filters.blur.inputRadius . Say instead of binding to
the control, however, we would rather animate the blur in code. In this case our key-path
changes relative to the object that contains the filter to be animated. The key-path becomes
filters.blur.inputRadius as the base object, blurLayer , rather than the AppDelegate .
In either case, notice we have employed the name we gave to our filter, blur , in the key-path.
Look ahead to Listing 6-6 that demonstrates how this is used when creating an animation.
Search WWH ::




Custom Search