Contents

shouldInvalidateLayout(forPreferredLayoutAttributes:withOriginalAttributes:)

Asks the layout object if changes to a self-sizing cell require a layout update.

Declaration

func shouldInvalidateLayout(forPreferredLayoutAttributes preferredAttributes: UICollectionViewLayoutAttributes, withOriginalAttributes originalAttributes: UICollectionViewLayoutAttributes) -> Bool

Parameters

  • preferredAttributes:

    The layout attributes returned by the cell’s Preferredlayoutattributesfitting(_:) method.

  • originalAttributes:

    The attributes that the layout object originally suggested for the cell.

Return Value

true if the layout should be invalidated or false if it should not.

Discussion

When a collection view includes self-sizing cells, the cells are given the opportunity to modify their own layout attributes before those attributes are applied. A self-sizing cell might do this to specify a different cell size than the one the layout object provides. When the cell provides a different set of attributes, the collection view calls this method to determine if the cell’s change requires a larger layout refresh.

If you are implementing a custom layout, you can override this method and use it to determine if your layout should be invalidated based on the specified attributes. The default implementation of this method returns false.

See Also

Invalidating the layout