Based on https://github.com/pgpt10/DragAndDrop-CollectionView
By using
self.collectionView.dragInteractionEnabled = true
self.collectionView.dragDelegate = self
self.collectionView.dropDelegate = self
Once you long press anywhere within a collection view cell, the following function will be triggered
extension DragDropViewController : UICollectionViewDragDelegate
{
func collectionView(_ collectionView: UICollectionView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem]
{
let item = collectionView == collectionView1 ? self.items1[indexPath.row] : self.items2[indexPath.row]
let itemProvider = NSItemProvider(object: item as NSString)
let dragItem = UIDragItem(itemProvider: itemProvider)
dragItem.localObject = item
return [dragItem]
}
However, I have a different requirement.
I have a collection which looks as the following
I wish when user tap (not long press) on the right 3 horizontal lines icon, he can immediately perform drag and reorder. Tapping other region, or long press on the cell, will not have drag and reorder effect.
May I know how can I achieve so?
Some notable app in App Store which able to achieve such feature
I notice Google Keep in App Store, able to achieve such feature. By just tapping on the left most icon in their Todo list, we can immediately reorder the Todo list item.
Wondering how they did that?
from How to you activate drag and order mode immediately after you tap on a button


No comments:
Post a Comment