16

I have a UICollectionView that contains some large UICollectionViewCells. These cells are so large that they completely fill the UICollectionView bounds and extend off screen.

The problem is that the large cells are removed from the UICollectionView and queued for reuse while they are still displayed, resulting in a blank view. If I continue scrolling on the blank UICollectionView area, eventually the final portion of the cell appears and the start of the next cell appears in exactly the right place.

I've effectively disabled cell reuse and the problem still occurs apparently because the UICollectionView thinks that the cell is no longer displayed since no corner is within the bounds of the collection view.

To demonstrate make a collection view that is a single column and have a cell that is 10000px tall, when scrolling over the very tall cell it will disappear after about 1000px of content is scrolled off the screen and will reappear to display the final 1000px of content for the cell.

You can download a simple prototype app that displays this problem at: http://jack.cox.s3.amazonaws.com/collectionviewprototype.zip

Kingsley
  • 14,398
  • 5
  • 31
  • 53
Jack Cox
  • 3,290
  • 24
  • 25
  • I am having the same issue, not sure how to solve it, did you manage to fix it? – Tomasz Zabłocki Nov 13 '12 at 23:00
  • I worked around it. The requirements of my app allowed me to just put it all into a single UIScrollView. I did open a bug report with Apple but have not heard anything back. – Jack Cox Nov 14 '12 at 21:47
  • @JackCox the download link isn't working now. Can you put it back up somewhere? Maybe stick it on Github? – mattjgalloway Dec 03 '12 at 10:54
  • 1
    I have filed a radar for this as well, FWIW. – mattjgalloway Dec 03 '12 at 11:57
  • Same problem here. Any news anyone? – Kai Huppmann Jan 09 '13 at 15:01
  • Since I did further investigations, I posted my own, more detailed question at http://stackoverflow.com/questions/14254222/large-uicollectionviewcell-stopped-being-displayed-when-scrolling – Kai Huppmann Jan 10 '13 at 09:11
  • 1
    i posted an hacky answer to @kai question – Jonathan Cichon Jan 10 '13 at 14:00
  • 1
    Can you guys post the link to the radar so I can dup it? I'm also having trouble with this. – kvn Feb 07 '13 at 16:09
  • I've posted a another possible answer to the other question similar to this one. http://stackoverflow.com/questions/14254222/large-uicollectionviewcell-stopped-being-displayed-when-scrolling – kvn Feb 08 '13 at 16:26
  • I believe this notion of a collection cell that is bigger than the bounds of the view does not sit right with the collection view paradigm. – Morkrom Dec 13 '13 at 21:05

4 Answers4

1

This issue happened for me along with this warning in the debug log:

the behavior of the UICollectionViewFlowLayout is not defined because: the item height must be less that the height of the UICollectionView minus the section insets top and bottom values.

It seems that the out of the box UICollectionViewFlowLayout does not support cells larger than the screen.

Rishil Patel
  • 1,977
  • 3
  • 14
  • 30
Robert
  • 65
  • 1
  • 8
0

This issue is being tracked as radar #12889164

azsromej
  • 1,619
  • 13
  • 15
0

Try this fix if you are still looking for a quick solution: When a cell is detected to have a bigger height than the collectionview holding it, the collection view simply needs to be larger than the cell. So set the collecitonView frame to be bigger and correct the content and indicator insets.

- (void)updateCollectionViewForLargeCellHeight:(CGFloat)largeCellHeight {
    CGFloat currentCollectionViewHeight = CGRectGetHeight(self.collectionView.frame);
    if (largeCellHeight > currentCollectionViewHeight) {
        self.collectionViewBottomConstraint = -largeCellHeight; 
        //This is the bottom constraint of the collectionView to its superview. 
        //If you are not using constraints, simply set the frame for the collectionView
        UIEdgeInsets edgeInset = UIEdgeInsetsMake(0, 0, largeCellHeight, 0);
        self.collectionView.contentInset = edgeInset;
        self.collectionView.scrollIndicatorInsets = edgeInset;
        [self.collectionView needsUpdateConstraints];
    }
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    CGSize size;
    [self updateCollectionViewForLargeCellHeight:size.height];
    return size;
}
jyliang
  • 198
  • 2
  • 7
0

I have used UICollectionView with cells of the size of the screen. For iPad the cell size was 768x1024. And haven't found any issues. Please make sure that you have set the Min Spacing For Cells and For Lines are 0 Also return correct CGSize and UIEdgeInsets as follows


- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    CGSize retval;
    retval.width=maxWidth; //768 in case of iPad
    retval.height=maxHeight; //1024 in case of iPad
    return retval;
}

- (UIEdgeInsets)collectionView:
(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
return UIEdgeInsetsMake(0 , 0, 0, 0);
}
Ajith Tom
  • 31
  • 6