I have two sections in my UICollectionView. I would like to be able to drag cells within each section but not between them.
I am using a long press gesture recognizer to animate the cell drag movement so I could check that the drop location is not in a different section. Is there a way to determine a section's frame?
Or is there a simpler way?
In the
UICollectionViewDropDelegate, this protocolfunc collectionView(_ collectionView: UICollectionView, dropSessionDidUpdate session: UIDropSession, withDestinationIndexPath destinationIndexPath: IndexPath?) -> UICollectionViewDropProposalcan help with it.Check the sample below for how I prevent an item being dragged from one section to the other section:
In UICollectionViewDragDelegate, we use the
itemsForBeginningfunction to pass information about the object. You can see that, I passed the index and item to thelocalObjectIn UICollectionViewDropDelegate, I did this:
According to Apple:
What I Did: I've a couple of restrictions to cover:
GIF