CAFilter

From iPhone Development Wiki
Revision as of 10:03, 15 December 2009 by KennyTM~ (talk | contribs) (Created page with 'CAFilter is an Objective-C wrapper for creating static or transition image filters. == Applying filters to layers == Although the SDK says that the <tt>filters</tt> propert…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

CAFilter is an Objective-C wrapper for creating static or transition image filters.

Applying filters to layers

Although the SDK says that the filters property is unused, you can actually apply filter effects with it, for example, to apply a Gaussian blur filter for a window:

CAFilter* filter = [CAFilter filterWithName:@"gaussianBlur"];
[filter setValue:[NSNumber numberWithFloat:5] forKey:@"inputRadius"];
window.layer.filters = [NSArray arrayWithObject:filter];

Builtin static filters

Layers with filters applied, in order: (1) no filter; (2) gaussianBlur; (3) multiplyColor; (4) pageCurl

gaussianBlur

The gaussianBlur filter can apply a Gaussian blur effect to the layer. It accepts a float parameter, inputRadius, which specifies the strength of blurring.

multiplyColor

This will multiply an inputColor to the layer.

pageCurl

The pageCurl filter gives the layer a page curl effect. It accepts 3 float parameters:

  • inputTime (from 0 to 1).
  • inputAngle (in radian, must not be a multiple of π/2).
  • inputRadius (in pixel, the radius of the curled part).

Transition filters

Transition filters also uses CAFilter as the interface, as CATransition also has a filter property. But the transition filters cannot be treated as static filters and applied to layers directly.

References