Contents

setCollectionViewLayout(_:animated:completion:)

Changes the collection view’s layout and notifies you when the animations complete.

Declaration

func setCollectionViewLayout(_ layout: UICollectionViewLayout, animated: Bool, completion: ((Bool) -> Void)? = nil)

Parameters

  • layout:

    The new layout object for the collection view.

  • animated:

    Specify True if you want to animate changes from the current layout to the new layout specified by the layout parameter. Specify False to make the change without animations.

  • completion:

    The block that’s executed when the layout transition finishes or is terminated by the user. This block takes the following parameter:

    finished

    A Boolean indicating whether the transition completed successfully. This parameter is True if the transition finished and the new layout is installed. It’s False if the user aborted the transition and returned to the old layout.

Discussion

This method initiates a layout change programmatically, notifying you when the transition is complete. If you choose to animate the layout change, the animation timing and parameters are controlled by the collection view.

See Also

Changing the layout