0

I'm trying to expand a cell vertically when pressed. At the moment the cell expands, but it just overlaps the other cells around it.

Any suggestion on how to use constraints to have the other cells adjust for this change in size?

Here is the code I am using:

UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];

  [UIView transitionWithView:collectionView
                    duration:.5
                     options:UIViewAnimationCurveEaseIn
                  animations:^{

                    cell.frame = CGRectMake(cell.frame.origin.x, cell.frame.origin.y, 500, cell.frame.size.height);

                    [cell setBackgroundColor:[UIColor greenColor]];
                  } completion:^(BOOL finished) {


                  }];

EDIT: This is not a duplicate as the previous question does not solve my issue.

spogebob92
  • 1,334
  • 3
  • 22
  • 30
  • possible duplicate of [UICollectionView: Animate cell size change on selection](http://stackoverflow.com/questions/13780153/uicollectionview-animate-cell-size-change-on-selection) – Marius Constantinescu Sep 01 '15 at 11:11

1 Answers1

1

The easiest way to animate a collection view cell is to reload the cell and return a new size from the sizeForItemAtIndexPath: method. After you've setup your datasource controller to do this just reload the layout with

[collectionView setCollectionViewLayout:[[UICollectionViewFlowLayout alloc] init] animated:YES];

This gives a very smooth animation.

Samhan Salahuddin
  • 2,024
  • 1
  • 15
  • 24