0

I have a UICollectionView in UISplitViewController with a custom UICollectionViewLayout which implements:

  • prepareLayout to store the attributes with right frames (based on orientation);
  • collectionViewContentSize to return the right collection view size based on the orientation
  • layoutAttributesForItemAtIndexPath just returns the stored attributes
  • layoutAttributesForElementsInRect check for the intersections

My layout looks like this in portrait mand landscape mode:

    Portrait      Landscape

Now, the problem is that when I change the orientation of the screen, I use this function to trigger the layout update:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    [headlinesCollectionView performBatchUpdates:nil completion:nil];
}

and this changes instantly the cell frame size to the new one; however the cell position get animated. Before trying this I used invalidateLayout, which does even a worse job since it doesn't animate either the size or the position.

Any idea on how I could make this work? The cell should get resized AND move whilst the animation occurs.

entropid
  • 6,130
  • 5
  • 32
  • 45
  • Layout has a method that you can override, something like invalidateLayoutOnBoundsChange: – pronebird Jan 11 '15 at 23:10
  • @Andy The layout gets invalidated and re-drawn correctly. The problem is that the cells snaps to the new size instead of gracefully animating. – entropid Jan 11 '15 at 23:13
  • Try implementing https://developer.apple.com/library/ios/documentation/UIKit/Reference/UICollectionViewLayout_class/index.html#//apple_ref/occ/instm/UICollectionViewLayout/shouldInvalidateLayoutForBoundsChange: – pronebird Jan 11 '15 at 23:14
  • And stop manual invalidation on rotation – pronebird Jan 11 '15 at 23:15
  • I followed your instructions and if the bounds change, that method return now YES and the transaction occurs. However, the cells are not resized, they merely cross-fade. :( – entropid Jan 11 '15 at 23:41
  • How about http://stackoverflow.com/a/12834768/351305 – pronebird Jan 12 '15 at 09:49

0 Answers0