lxcid / LXReorderableCollectionViewFlowLayout

Extends `UICollectionViewFlowLayout` to support reordering of cells. Similar to long press and pan on books in iBook.
http://lxcid.com/
MIT License
1.86k stars 328 forks source link

Animation glitches when reordering cells of different size #26

Open selasie opened 11 years ago

selasie commented 11 years ago

Hi, i've been using your layout for a while and encountered following problem: Basically, I mimic table view via UICollectionView (cell width = screen width, no gaps between cells) to be able to reorder my cells -> but I need to display reordering control in a different location inside my custom cell, but, alas, UITableViewCell do not allow me to do this without some trickery.

I forked your repo here - https://github.com/selasie/LXReorderableCollectionViewFlowLayout/commit/a9dd083bd16367bc99d2eb7471a50472c0a112d2

And fixed following issue (although it might be specific to my project only, but it might help someone, someday):

When I reorder cells of different height (especially, when you drag cell with lesser height above cell with bigger height) there is a lot of glitches with inserting / deleting cells animation. I restricted movement only to Y-axis (in handlePanRecoginzer: I use only y component of translation point), and modified invalidateLayoutIfNecessary method to handle following condition: If we moving same direction (for now, I check only for vertical movement up and down) and trying to swap cells with index path similar to previously swapped cells (e.g. we swapped cells at indexes 0 and 1, and now trying to swap cell at index 1 with cell at index 0) - we assume that this scenario is wrong and do nothing, otherwise - continue swapping.