Instance Property

filter

An optional Core Image filter object that provides the transition.

Declaration

var filter: Any? { get set }

Discussion

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() {
    super.viewDidLoad()
    
    view.layerUsesCoreImageFilters = true
    
    view.layer = CALayer()
    
    transitioningLayer.frame = CGRect(x: 10, y: 10,
                                      width: 320, height: 160)
    
    view.layer!.addSublayer(transitioningLayer)
    
    // Initial "red" state
    transitioningLayer.backgroundColor = NSColor.red.cgColor
    transitioningLayer.string = "Red"
}
     
func runTransition() {
    let transition = CATransition()
    transition.duration = 2
    
    transition.filter = CIFilter(name: "CICopyMachineTransition")
    transitioningLayer.add(transition,
                           forKey: "transition")
    
    // Transition to "blue" state
    transitioningLayer.backgroundColor = NSColor.blue.cgColor
    transitioningLayer.string = "Blue"
}

Special Considerations

This property is not supported on layers in iOS.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software