I am having a problem where it seems that my UICollectionView
thinks that my screen is smaller (iPad Air) , and he fail to load the next cells in time ,and load them in late-cause "holes".
I have 2 columns,dynamic cell height,and subclassed the layout to get constant vertical spacing.
I could see now, that the only thing that solves this problem for me = let the UICollectionView load more cells so i can scroll down and NOT see a blank spaces, is to set the height of the collectionView to be much higher than screen size . Now, all cells are loaded just in time when scrolling down. BUT , now when i scroll back up , i get the same effect of empty spaces . Empty means that half screen is empty ,and only when i continue scrolling ,he loads these cells in late.
I just can't seem to solve this issue for a while, but i think i might do something wrong with setting the relationship between the layout and the colleciontview content sizes .
Here is how i set them :
//collection view
TopAlignedCollectionViewFlowLayout *layout=[[TopAlignedCollectionViewFlowLayout alloc] init];
CGRect size=CGRectMake( ([UIScreen mainScreen].bounds.size.width-collectionWidth)/2,
upperLineMargin, collectionWidth, (6.*[UIScreen mainScreen].bounds.size.height )); //seting *6 soves the problem.
self.GridView=[[UICollectionView alloc] initWithFrame:size collectionViewLayout:layout];
[self.GridView registerClass:[GridCell class] forCellWithReuseIdentifier:@"Cell"];
//[ layout setItemSize:CGSizeMake(collectionWidth, [UIScreen mainScreen].bounds.size.height )];
This issue only happens after i was trying to subclass the layout for the equal spacing between rows. We are now in the situation that we don't have where to go, and we can't use the collection with this bug, because that temporary blank spaces not looks good .
- (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewLayoutAttributes* currentItemAttributes = [super layoutAttributesForItemAtIndexPath:indexPath];
if (indexPath.item < numColumns)
{
CGRect f = currentItemAttributes.frame;
f.origin.y = 0;
currentItemAttributes.frame = f;
return currentItemAttributes;
}
NSIndexPath* ipPrev = [NSIndexPath indexPathForItem:indexPath.item-numColumns inSection:indexPath.section];
CGRect fPrev = [self layoutAttributesForItemAtIndexPath:ipPrev].frame;
CGFloat YPointNew = fPrev.origin.y + fPrev.size.height + 10;
CGRect f = currentItemAttributes.frame;
f.origin.y = YPointNew;
currentItemAttributes.frame = f;
return currentItemAttributes;
}