Is there a method to check the UICollectionView item drag cancellation if the item wasn't moved?

一曲冷凌霜 提交于 2019-12-10 16:12:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!