With the release of iOS-11, Apple introduced Drag and Drop in UITableView and UICollection with a specialized API that works on the concept of Interactions (something like gestures).
UITableView and UICollectionView have similar APIs to support Drag and Drop with some small differences. So, in this sample I'll be showing how you can integrate drag and drop in UICollectionView.
Here you can find the complete implementation details of drag & drop in table view and collection view.
- iPhone (In iPhone, Drag and Drop is supported only in the same app. In iPad, Drag and Drop is supported within multiple apps.)
- iOS 11
- Swift 4
- UICollectionView
- UICollectionViewDragDelegate and UICollectionViewDropDelegate to support Drag and Drop in UICollectionView.
- Reordering cells in UICollectionView.
- Controlling drag speed while reordering - reorderingCadence.
- Copying data within multiple Collection Views.
- Dragging and dropping single as well as multiple items.
- What the element looks like when it is dragged around - Drag Preview.
- How to handle drops i.e. copy/move/cancel/forbidden - Drop Proposal.
- Performing actual drop in same/different UICollectionView.
The project describes Drag and Drop using 2 UICollectionViews and supports:
- Reordering - Moving an element from source to destination indexpath within same Collection View.
- Copying an element from 1st Collection View to 2nd CollectionView at a particular destination indexpath.
- Forbidding the movement(copying/moving) of an element from 2nd Collection View to 1st CollectionView.