Say you want to have grid layout with cells always half the size of the screen’s width. You want to maintain that layout in both portrait and landscape. Since iOS 8 that can’t be easier, with the right incantations.
Then add the following method into it:
1 2 3 4 5 6 7 8 9
The key here is casting returned context from
UICollectionViewFlowLayoutInvalidationContext which allows you to toggle the
invalidateFlowLayoutDelegateMetrics property. That will tell UIKit that it should re-query FlowLayout’s delegate for the sizes.
In the collection view controller, make sure it’s set to adopt
UICollectionViewDelegateFlowLayout protocol and then add this delegate call:
1 2 3 4 5 6