UICollectionView effective drag and drop
This might help
https://github.com/lxcid/LXReorderableCollectionViewFlowLayout
This is extends the UICollectionView
to allow each of the UICollectionViewCells
to be rearranged manually by the user with a long touch (aka touch-and-hold). The user can drag the Cell to any other position in the collection and the other cells will reorder automatically. Thanks go to lxcid for this.
Here is an alternative:
The differences between DraggableCollectionView and LXReorderableCollectionViewFlowLayout are:
- The data source is only changed once. This means that while the user is dragging an item the cells are re-positioned without modifying the data source.
- It's written in such a way that makes it possible to use with custom layouts.
- It uses a
CADisplayLink
for smooth scrolling and animation. - Animations are canceled less frequently while dragging. It feels more "natural".
- The protocol extends
UICollectionViewDataSource
with methods similar toUITableViewDataSource
.
It's a work in progress. Multiple sections are now supported.
To use it with a custom layout see DraggableCollectionViewFlowLayout
. Most of the logic exists in LSCollectionViewLayoutHelper
. There is also an example in CircleLayoutDemo showing how to make Apple's CircleLayout example from WWDC 2012 work.