Protocol

NSCollectionViewElement

The NSCollectionViewElement protocol defines the methods for managing content in a collection view. Adopt this protocol in the classes that you use to display content for items, supplementary views, and decoration views in a collection view. The methods of this protocol are optional and provide support for applying layout attributes and for cleaning up elements when they move offscreen and are recycled.

Overview

Collection view items—that is, instances of the NSCollectionViewItem class—already adopt this protocol. For supplementary and decoration views, adopt this protocol in the custom view classes you use to represent that content.

Symbols

Reusing Elements

func prepareForReuse()

Performs any necessary cleanup to prepare the element for use again.

Managing Layout Changes

func preferredLayoutAttributesFitting(NSCollectionViewLayoutAttributes)

Asks your element if it wants to modify any layout attributes before they are applied.

func apply(NSCollectionViewLayoutAttributes)

Applies the specified layout attributes to the element.

func willTransition(from: NSCollectionViewLayout, to: NSCollectionViewLayout)

Tells the element that the layout object of the collection view is about to change.

func didTransition(from: NSCollectionViewLayout, to: NSCollectionViewLayout)

Tells the element that the layout object of the collection view changed.