An object that contains layout-related attributes for an element in a collection view.
- macOS 10.11+
During the layout, the layout object creates instances of
NSCollection for each element displayed in the collection view. The layout attributes describe the position of an element and other information such as its alpha and position on the z axis. The collection view later applies the layout attributes to the onscreen elements.
The only time you interact with layout attribute objects is when you implement a custom layout, and the interactions are straightforward. When asked for layout attributes for a specific element, your layout object uses the methods of this class to create an appropriate instance of the class based on the type of the requested element. It then configures the properties of the object and returns it to the requester.
If you implement a custom layout object and your layout object requires additional attributes, you can subclass
NSCollection and add custom properties to your subclass. In your subclass, be sure to do the following:
initmethod with no parameters to initialize your subclass.
Implement support for the
NSCopyingprotocol. The collection view caches layout attribute objects for later use.
Override the inherited
ismethod to perform any relevant equality checks.
Supporting equality checks is important because of how the collection view manages layout attributes. As an optimization, the collection view applies layout attributes only when they change. When the layout object returns a layout attributes object, the collection view checks to see if the new attributes are equal to any cached attributes. Therefore, if you want to include any new properties in the equality check, you must override the
In addition to defining your
NSCollection subclass, override the
layout method of your layout object. That method is a funnel point for creating new layout attribute objects. Returning your custom class from that method ensures that the correct class is instantiated.