代码之家  ›  专栏  ›  技术社区  ›  Alexey Chekanov

如果项目未移动,是否有方法检查UICollectionView项目拖动取消?

  •  8
  • Alexey Chekanov  · 技术社区  · 6 年前

    我使用拖放来重新排列collectionView。开始拖动时,我会更改collectionView可视化。要更改回来,我需要一个在任何情况下都会执行的方法。现在,如果我立即开始拖动并释放触摸,则不会执行以下任何方法:

    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)
    

    非常感谢。

    2 回复  |  直到 6 年前
        1
  •  3
  •   Alexey Chekanov    6 年前

    如果使用标准UICollectionViewDragDelegate实现,则可以使用 func dragStateDidChange(_ dragState: UICollectionViewCellDragState) 单元格类本身的 例如:

    override func dragStateDidChange(_ dragState: UICollectionViewCellDragState) {
    
        switch dragState {
    
        case .none:
            //
        case .lifting:
            //
        case .dragging:
            //
        }
    }
    
        2
  •  1
  •   Alexey Chekanov    6 年前

    来自WWDC“ Introducing Drag and Drop “视频似乎处理电梯及其取消的正确位置是 dragInteraction(_:willAnimateLiftWith:session:) 方法

    enter image description here