Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animate UICollectionViewFlowLayout subclass UICollectionViewLayoutAttributes frame changes

I have sub classed UICollectionViewFlowLayout, and in that sub class, I'm changing the UICollectionViewLayoutAttributes frames, so that they would appear larger or smaller - depending on their position on screen.

I'm performing the frame changes in layoutAttributesForElementsInRect: And as well returning it in layoutAttributesForItemAtIndexPath: I'm returning YES in shouldInvalidateLayoutForBoundsChange:

All is working well, but the cells do not animate the changes of the frame.

Am i missing Something? Why are the changes are not being animated?

Thanks.

like image 388
Raz Avatar asked Apr 07 '14 07:04

Raz


1 Answers

SOLVED.

There is no "animation function", or anything similar, since changing the frames of items of a collection view inside your own custom (flow) lay out just can't be animated.

The solution to the problem is writing an algorithm that calculates all the relevant frames that the method layoutAttributesForElementsInRect: provides, so that setting the frame of an item will respectfully set another item's frame an will compensate for the added size, or reduced size.

like image 99
Raz Avatar answered Nov 13 '22 08:11

Raz