Instance Property


An optional Core Image filter object that provides the transition.


var filter: Any? { get set }


If specified, the filter must support both kCIInputImageKey and kCIInputTargetImageKey input keys, and the kCIOutputImageKey output key. The filter may optionally support the kCIInputExtentKey input key, which is set to a rectangle describing the region in which the transition should run. If filter does not support the required input and output keys the behavior is undefined.

Defaults to nil. When a transition filter is specified the type and subtype properties are ignored.

The NSView that contains the transitioning layer must have its layerUsesCoreImageFilters set to true.

Listing 1 shows how you can transition between the two states of a CATextLayer named transitioningLayer. When the layer is first created, its backgroundColor is set to red and its string property is set to Red. When the runTransition() function is called, a new CATransition object is created and added to transitioningLayer, and the state of the layer is changed so that its background color is blue and its rendered text reads Blue.

The end result is that the transition animates from the red state to the blue state using a CICopyMachineTransition transition.

Listing 1

Transitioning between a layer's states

override func viewDidLoad() {
    view.layerUsesCoreImageFilters = true
    view.layer = CALayer()
    transitioningLayer.frame = CGRect(x: 10, y: 10,
                                      width: 320, height: 160)
    // Initial "red" state
    transitioningLayer.backgroundColor =
    transitioningLayer.string = "Red"
func runTransition() {
    let transition = CATransition()
    transition.duration = 2
    transition.filter = CIFilter(name: "CICopyMachineTransition")
                           forKey: "transition")
    // Transition to "blue" state
    transitioningLayer.backgroundColor =
    transitioningLayer.string = "Blue"

Special Considerations

This property is not supported on layers in iOS.