【问题标题】:How to get the frame or the center of a cell that's being dragged with iOS11's drag-n-drop APIs如何使用 iOS11 的拖放 API 获取正在拖动的单元格的框架或中心
【发布时间】:2018-08-25 14:18:04
【问题描述】:

我找到了一种在单元格被丢弃时获取单元格中心的方法。但是当我将它拖过collectionView时,我想知道它的中心。有谁知道我怎样才能得到它?

或者有更好的解决方案吗?我想要实现的是让用户将一个单元格放到另一个单元格上以创建文件夹,同时还让他重新排列单元格(换句话说,与 iOS 中的跳板相同)。

【问题讨论】:

    标签: ios swift uicollectionview


    【解决方案1】:

    解决了!

    您可以使用其中一种 UICollectionViewDropDelegate 方法。

    func collectionView(_ collectionView: UICollectionView, dropSessionDidUpdate session: UIDropSession, withDestinationIndexPath destinationIndexPath: IndexPath?) -> UICollectionViewDropProposal
    

    您可以在其中调用会话对象的 location(in: UIView) 方法。

    session.location(in: collectionView)
    

    更新

    这种方法的问题在于它会为您提供手指所在的位置,而不是单元格预览的中心。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-16
      • 1970-01-01
      • 2014-01-15
      • 1970-01-01
      • 2013-04-17
      • 1970-01-01
      • 2017-07-06
      • 1970-01-01
      相关资源
      最近更新 更多