0

I'm looking to override my UICollectionViewFlowLayout to cause the cells to slide when changing positions due to an orientation change. What I have currently is 3 cells per row in portrait and 4 cells per row in landscape but the only animation I can get is the default fading in when I change orientations.

I've been looking at using performBatchUpdates but I'm pretty sure that's not where I'll find the answer.

I've also been looking into the layoutAttributesForElementInRect and layoutAttributesForItemAtIndexPath which I think is where I'll find the answer. I'm not sure if I'll need to create a new attribute for the cells (previousCenter maybe) and use that as the starting point for new animations or maybe use performBatchUpdates using what should be the new frame as the value to change.

For the record all animation questions I've found have been about how to change animations for insertion and deletion of items which is not what I'm wanting to do.

hjpotter92
  • 78,589
  • 36
  • 144
  • 183
trevest
  • 1
  • 2

1 Answers1

0

Try

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(    NSTimeInterval)duration {
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    [self.collectionView reloadData];
}

and then add whatever you need to "slide" it at that point.

If you are using flowLayout or a subclass of it, it should automatically reposition the cells for you.If you subclass layout you might need to adjust the layoutattributes you return to correspond to the rotation. The animation should be done for you though.

SashaZd
  • 3,315
  • 1
  • 26
  • 48