Ios – Animating UICollectionView on orientation changes

iosiphoneuicollectionviewuiinterfaceorientation

Consider a UICollectionView that has a different number of items and a different layout (ie: spacing) on landscape and portrait orientation.

What needs to be done for these changes to be animated when the device is rotated? I couldn't find any mention of how to handle rotations on the Collection View Programming Guide.

Best Answer

It's not necessary to reload the collection view's data — invoking [collectionView.collectionViewLayout invalidateLayout] will cause the collection view to update its layout.

Overriding shouldInvalidateLayoutForBoundsChange: to return YES in a UICollectionViewLayout subclass will result in invalidateLayout being called automatically whenever the collection view's bounds change (including when its size changes and when the user scrolls its contents).

Related Topic