-3

I have a collection view with a series of cells inside of it. I am trying to figure out how when I click the cell it leaves a gap, and then how I would animate with a uiview sliding up in between. Essentially it would operate like this.

Cell Cell <--user clicks Cell

Cell UiView Cell Cell

Dan Quackenbush
  • 123
  • 1
  • 1
  • 6

1 Answers1

0

The way to accomplish this is to create a second type of cell (custom cell) that would be the cell you animate into place by sliding up in between.

Insert it into place using insertItemsAtIndexPaths. Link to apple docs here.

The parameter for this is an array of NSIndexPaths that you want to insert into the area.

In your case, the array would consist of one indexPath that would need to have item row of +1 after the cell that the user clicked on. Something like this...

 insertItemsAtIndexPaths([NSIndexPath(forItem: cellUserClickedOn+1, inSection: 0)]) 

Also you need to update the datasource to contain information about that cell that the collectionview pulls from in the same element position as the indexpath row position you are inserting.

Not sure what the default animation is for the UICollectionView but if its not what you want, you will have to customize it yourself. That will involve subclassing the UICollectionViewLayout class and customizing the movement. Here's a link to a so post that covers that

Community
  • 1
  • 1
bolnad
  • 4,533
  • 3
  • 29
  • 41