Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have been pulling my hair out over this for days and have found a solution for my situation that may help. In my case I have a collapsing photo layout like in the photos app on the ipad. It shows albums with the photos on top of each other and when you tap an album it expands the photos. So what I have is two separate UICollectionViewLayouts and am toggling between them with <code>[self.collectionView setCollectionViewLayout:myLayout animated:YES]</code> I was having your exact problem with the cells jumping before animation and realized it was the <code>contentOffset</code>. I tried everything with the <code>contentOffset</code> but it still jumped during animation. tyler's solution above worked but it was still messing with the animation.</p> <p>Then I noticed that it happens only when there were a few albums on the screen, not enough to fill the screen. My layout overrides <code>-(CGSize)collectionViewContentSize</code> as recommended. When there are only a few albums the collection view content size is less than the views content size. That's causing the jump when I toggle between the collection layouts.</p> <p>So I set a property on my layouts called minHeight and set it to the collection views parent's height. Then I check the height before I return in <code>-(CGSize)collectionViewContentSize</code> I ensure the height is >= the minimum height.</p> <p>Not a true solution but it's working fine now. I would try setting the <code>contentSize</code> of your collection view to be at least the length of it's containing view.</p> <p><strong>edit:</strong> Manicaesar added an easy workaround if you inherit from UICollectionViewFlowLayout:</p> <pre><code>-(CGSize)collectionViewContentSize { //Workaround CGSize superSize = [super collectionViewContentSize]; CGRect frame = self.collectionView.frame; return CGSizeMake(fmaxf(superSize.width, CGRectGetWidth(frame)), fmaxf(superSize.height, CGRectGetHeight(frame))); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload