问题
I use drag and drop to rearrange a collectionView. When I start the drag, I change the collectionView visualization. To change it back I need a method which will be executed in any case. Now if I start the drag and release the touch immediately, none of the following methods are executed:
not this:
func collectionView(_ collectionView: UICollectionView, dragSessionDidEnd session: UIDragSession)
not this:
func collectionView(_ collectionView: UICollectionView, dropSessionDidEnd session: UIDropSession)
not this:
func collectionView(_ collectionView: UICollectionView, performDropWith coordinator: UICollectionViewDropCoordinator)
Thank you.
回答1:
If you use the standard UICollectionViewDragDelegate implementation, you can react to the cell state change using the func dragStateDidChange(_ dragState: UICollectionViewCellDragState) of the cell class itself like:
override func dragStateDidChange(_ dragState: UICollectionViewCellDragState) {
switch dragState {
case .none:
//
case .lifting:
//
case .dragging:
//
}
}
回答2:
From the WWDC "Introducing Drag and Drop" video it seems that the right place to handle the lift and its cancellation is the dragInteraction(_:willAnimateLiftWith:session:) method.
来源:https://stackoverflow.com/questions/49681643/is-there-a-method-to-check-the-uicollectionview-item-drag-cancellation-if-the-it