Instance Property

wantsLayer

A Boolean value indicating whether the view uses a layer as its backing store.

Declaration

@property BOOL wantsLayer;

Discussion

Setting the value of this property to YES turns the view into a layer-backed view—that is, the view uses a CALayer object to manage its rendered content. Creating a layer-backed view implicitly causes the entire view hierarchy under that view to become layer-backed. Thus, the view and all of its subviews (including subviews of subviews) become layer-backed. The default value of this property is NO.

In a layer-backed view, any drawing done by the view is cached to the underlying layer object. This cached content can then be manipulated in ways that are more performant than redrawing the view contents explicitly. AppKit automatically creates the underlying layer object (using the makeBackingLayer method) and handles the caching of the view’s content. If the wantsUpdateLayer method returns NO, you should not interact with the underlying layer object directly. Instead, use the methods of this class to make any changes to the view and its layer. If wantsUpdateLayer returns YES, it is acceptable (and appropriate) to modify the layer in the view’s updateLayer method.

For layer-backed views, you can flatten the layer hierarchy by setting the canDrawSubviewsIntoLayer property to YES. To prevent a subview from having its contents flattened into this view’s layer, explicitly set the value of the subview’s wantsLayer property to YES.

In addition to creating a layer-backed view, you can create a layer-hosting view by assigning a layer directly to the view’s layer property. In a layer-hosting view, you are responsible for managing the view’s layer. To create a layer-hosting view, you must set the layer property first and then set this property to YES. The order in which you set the values of these properties is crucial.

In a layer-hosting view, do not rely on the view for drawing. Similarly, do not add subviews to a layer-hosting view. The root layer—that is, the layer you set using the layer property—becomes the root layer of the layer tree. Any manipulations of that layer tree must be done using the Core Animation interfaces. You still use the view for handling mouse and keyboard events, but drawing must be handled by Core Animation.

See Also

Managing the View’s Layer

wantsUpdateLayer

A Boolean value indicating which drawing path the view takes when updating its contents.

layer

The Core Animation layer that the view uses as its backing store.

- makeBackingLayer

Creates the view’s backing layer.

layerContentsPlacement

The current layer contents placement policy.

layerContentsRedrawPolicy

The contents redraw policy for the view’s layer.

canDrawSubviewsIntoLayer

A Boolean value indicating whether the view incorporates content from its subviews into its own layer.

layerUsesCoreImageFilters

A Boolean value indicating whether the view’s layer uses Core Image filters and needs in-process rendering.

NSViewLayerContentScaleDelegate

An optional layer delegate method for handling resolution changes.