Say I have a UICollectionView using a UICollectionViewFlowLayout and the following format:
1 2 3
4 5 6
7 8 9
I touch cell 9 and drag it over cell 6, moving cell 9 to where cell 6 is and cell 6 to where cell 9 was:
1 2 3
4 5 9
7 8 6
Is there any way to easily move and animate cell 6 to where cell 9 is as well as move and animate cell 9 to where cell 6 is? Or do I have to subclass UICollectionViewLayout? If I have to subclass UICollectionViewLayout, how would this be done? I've tried explicitly setting the centers of the cells in
-(UICollectionViewLayoutAttributes*)layoutAttributesForItemAtIndexPath:(NSIndexPath *)indexPath
but to no success.
After much head banging, the solution I found is to use
moveItemAtIndexPath:toIndexPath
inside ofperformBatchUpdates:completion
. According to the documentation forperformBatchUpdates:completion
:So, what I essentially did was
Swift code:
Have you tried re-ordering the items directly using moveItemAtIndexPath:toIndexPath: ?
-make sure you actually re-order the underlying model collection so that the changes stick when you do a full reload next time.