1

iOS9 implements a nice reordering feature for the UICollectionView.

At my CollectionViewController I implemented following code to get it work:

- (void)collectionView:(UICollectionView *)collectionView moveItemAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath 
{
    _cells[sourceIndexPath.row][1] = [NSString stringWithFormat:@"%li", (long)destinationIndexPath.row];
    _cells[destinationIndexPath.row][1] = [NSString stringWithFormat:@"%li", (long)sourceIndexPath.row];
    [self saveCellorder];
}

The 'cells' Array is just there to save the order of the Cells in the View

--

Now to my Problem/Question:

I got 2 different sized Cells in my CollectionView, when I drag a small cell over a small cell they change their places and everything is ok. Same happens when I drag a big cell over a big cell.

BUT when I drag a small cell over a big cell the big cell gets small and the small cell gets big. How can i prevent the cells from changing their size?

krushnsinh
  • 874
  • 1
  • 10
  • 11
Ni Nö
  • 51
  • 7

1 Answers1

1

I guess, you have you delegate method -collectionView:layout:sizeForItemAtIndexPath: implemented. This method returns not a size of the cell, strictly saying. It returns size of a cell at specified position. So, you should catch moment, when collection view order changes and respond to it in a manner, that tells -collectionView:layout:sizeForItemAtIndexPath: to return the right size.

Or, you can simply implement self-sizing collection view cells. Take a look at WWDC 2014 "What's New in Table and Collection Views". It is pretty easy Amazing©

For more on self-sizing cells : SO answer

Community
  • 1
  • 1
Sergii Martynenko Jr
  • 1,407
  • 1
  • 9
  • 18