HTKDragAndDropCollectionViewLayout
Custom UICollectionViewLayout that works together with a custom UICollectionViewCell to provide drag and drop for a UICollectionView. Works just like UITableView drag and drop. What's unique about this approach is that it does not need to create a "ghost" or "dummy" cell to provide the drag and drop functionality. I believe this method is simpler and less complex for the majority of use cases.
Adding to your project:
Cocoapods
CocoaPods is the recommended way to add HTKDragAndDropCollectionViewLayout to your project.
- Add a pod entry for HTKDragAndDropCollectionViewLayout to your Podfile
pod 'HTKDragAndDropCollectionViewLayout'
- Install the pod(s) by running
pod install
. - Subclass
HTKDragAndDropCollectionViewController
. - Setup
HTKDragAndDropCollectionViewLayout
properties (itemSize, lineSpacing, etc). - Subclass and use
HTKDraggableCollectionViewCell
which implements the gestures for dragging. - Implement
- (void)userDidEndDraggingCell:(UICollectionViewCell *)cell
and if theHTKDragAndDropCollectionViewLayout
finalIndexPath is not nil, insert the draggedIndexPath into the finalIndexPath's position. See example in project.
Sample video:
Screen shot:
Change log:
v0.0.1: Initial project commit v0.1.0 - v0.1.2: Bug fixes - Don't use this version, I broke it. v0.1.3: Current stable version. This version is greatly enhanced over the original version. It now supports rotation, and inserting of items. Currently inserting only works to the "end" of the data source. So, if you have 10 items in your collectionView and wish to insert, adding the item to indexPath 0,10 will work fine, while adding to indexPath 0,5 would not. This should be corrected pretty soon.
Questions? Email: [email protected] or Web: http://www.henrytkirk.info