1
votes

In my use of

- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect

in a custom layout subclass, I only see rect coordinate values that are mostly multiples of 1024. Is this right? What am I doing wrong?

Here are the values I see as I scroll around a UICollectionView with dimensions of width=3780, height=3310, for rect (duplicates removed):

 rect {{0, 0}, {1024, 1024}}
 rect {{0, 0}, {2048, 1024}}
 rect {{0, 0}, {2048, 2048}}
 rect {{0, 1024}, {2048, 1024}}
 rect {{0, 1024}, {2048, 2048}}
 rect {{0, 2048}, {2048, 1024}}
 rect {{0, 2048}, {2048, 1262}}
 rect {{1024, 2048}, {2048, 1262}}
 rect {{2048, 2048}, {1732, 1262}}
 rect {{2048, 2048}, {1732, 1024}}
 rect {{2048, 1024}, {1732, 2048}}
 rect {{1024, 1024}, {2048, 2048}}
 rect {{1024, 1024}, {2048, 1024}}
 rect {{1024, 0}, {2048, 2048}}
 rect {{1024, 0}, {1024, 2048}}
 rect {{0, 0}, {2048, 2048}}
 rect {{0, 0}, {2048, 1024}}
 rect {{-1024, 0}, {2048, 1024}}
 rect {{-1024, 0}, {2048, 2048}}
 rect {{-0, 0}, {1024, 2048}}
 rect {{0, 0}, {2048, 2048}}
 rect {{1024, 0}, {2048, 2048}}
 rect {{2048, 0}, {1732, 2048}}

What I expect to see is for the origin to reflect the contentOffset, and the size to always be the size of the screen.

Any ideas what is going on?

Two pieces of detail:

I'm testing on an iPad, and I invalidate the layout on bounds change, which is why layoutAttributesForElementsInRect is getting called when I scroll around.

-(BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds
{
    return YES;
}
1
I can't rely on these weird bounds changes. I'm getting the same thing. For my purposes, I just made a rect that was at origin .zero and size collectionView.contentSize. This always gave me every item, which I can check against the visible screen rect. - CIFilter

1 Answers

1
votes

Apple's answer to this on devforums was to adhere to their docs and return any elements that intersect the rect parameter without regards to whether rect makes sense or not.