1
votes

I have a UICollectionView for which I've implemented a custom subclass of UICollectionViewFlowLayout and implemented the layoutAttributesForElementsInRect method. My view is scrollable and I've implemented the shouldInvalidateLayoutForBoundsChange method to return YES. So every time I scroll, layoutAttributesForElementsInRect gets called.

But when I'm scrolling around in the top half of my view, the rect it gets called with is the rect for the whole collection (e.g. {{0, 0}, {320, 1136}} {{0, 567}, {320, 548}}), and when I scroll past halfway the rect becomes only the bottom half (i.e. {{0, 568}, {320, 568}} {{0, 568}, {320, 548}}). This completely breaks my layout. I need layoutAttributesForElementsInRect to always get called with the rect for the whole view.

Why did it use that other rect, and how can I turn off the rect-changing behavior?

1

1 Answers

0
votes

Oh ho, my collection view had two elements and when I was rendering both it would lay out the rectangle for both of them but when I was rendering one it would lay out the rectangle for one of them. I can fix it by counting up the number of elements and multiplying by the dimensions of each one to get the right rect.