I\'m displaying lots of image cells in an UICollectionView. With one button I would like to be able to group all my cell over the first one.
This is working well but
Animations won't work from within the method you are calling them from.
To change the layout and animate to a new one, the simplest method is to call performBatchUpdates
on your collection view, with nil
for each block parameter. This invalidates your layout and animates to the new one for you.
Before doing this, you'd tell the layout object that you want the new layout to occur. Also, inside layoutAttributesForElementsInRect
, simply check your Boolean variable and apply the grouped frame (probably center would be better) to all attributes as you are doing now, but without animation. You'll also need to reproduce this code in layoutAttributesForElementAtIndexPath
.
So, in summary: