问题描述
我使用拖放来重新排列collectionView。当开始拖动时,将更改collectionView可视化。要改回它,我需要一个在任何情况下都可以执行的方法。现在,如果我开始拖动并立即释放触摸,则不会执行以下任何方法:
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)
谢谢
推荐答案
如果您使用标准的UICollectionViewDragDelegate实现,则可以使用 func dragStateDidChange(_ dragState:UICollectionViewCellDragState)单元格类本身的 ,例如:
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:
//
}
}
这篇关于是否有一种方法可以检查UICollectionView项拖动是否取消(如果未移动项)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!