Redraw cells after UICollectionViewFlowLayout invalidates its layout

ios, uicollectionview, uicollectionviewlayout

Solution

When your cells change size, it's up to them how to handle that (stretching vs redrawing). This is controlled by the UIView `contentMode` property; try setting it to `UIViewContentModeRedraw` to cause resizing to invalidate your views contents like `setNeedsDisplay:` would.

If you're using CALayers directly as sub-layers of your cell, you can set their `needsDisplayOnBoundsChange` to `YES` in order to get the same effect.

Problem

When you invalidate layout on a `UICollectionViewFlowLayout` it creates a bunch of new layout attributes for each of your cells; it doesn't tell your cells to redraw however, which causes distortions in any Layer drawings. I don't want to tell my collection to reload its data because this removes any nice transitions you have between flow attributes : I have a grid layout transitioning into a coverflow for example. I need a way for the `UICollectionViewController` class to tell the cells to call their `[setNeedsDisplay]` method after being given the layout attributes.

Original source