5

我需要将一个单元格从CollectionView一个拖放到 CollectionView两个。一个 CollectionView 内的拖放是没有问题的,但我怎样才能将 Cell 从 CollectionView One 移到 CollectionView 2?

有任何想法吗?任何已经解决了这个问题的项目或框架?感谢您的帮助!

4

3 回答 3

4

https://github.com/Ice3SteveFortune/i3-dragndrop Check this out - its a helper I'm working on to achieve just that. It also supports tableviews

UPDATE

I've recently released the second version of this codebase, called BetweenKit. Its now a fully-fledged drag-and-drop framework.

Hope it proves useful !

于 2013-12-07T16:49:23.083 回答
2

当您从第一个集合视图中选择单元格时,将其从此集合视图中删除,创建一个新视图作为该单元格的副本,并将其作为超级视图的子视图放在所有视图之上。使用平移手势使该视图可移动。一旦你“放下”这个中间单元,检测它的位置并将它添加到当前的集合视图中。

于 2013-07-02T15:45:43.307 回答
2

好的,这是以下示例中最简单的流程:

在此处输入图像描述

  1. UIGestureRecognizer为每个添加UICollectionView
  2. 用一种方法连接每个手势识别器:

    @IBAction func longPressGestureChanged(recognizer: UILongPressGestureRecognizer) { ... }
    
  3. 在为每个UIViewController添加:@IBOutletUICollectionView

    @IBOutlet var collectionViewGreen: UICollectionView!
    @IBOutlet var collectionViewYellow: UICollectionView!
    
  4. 实现手势识别器方法来检测变化:

    @IBAction func longPressGestureChanged(recognizer: UILongPressGestureRecognizer) {
    
        let globalLocation = recognizer.locationInView(view)
    
        if CGRectContainsPoint(collectionViewGreen.frame, globalLocation) {
    
            //you cover green collection view
            let point = view.convertPoint(globalLocation, toView: collectionViewGreen)
            if let indexPath = collectionViewGreen.indexPathForItemAtPoint(point) {
               //you cover cell in green collection view
            } else {
                //you do not cover any of cells in green collection view
            }
    
        } else if CGRectContainsPoint(collectionViewYellow.frame, globalLocation) {
    
            //you cover yellow collection view
            let point = view.convertPoint(globalLocation, toView: collectionViewYellow)
            if let indexPath = collectionViewYellow.indexPathForItemAtPoint(point) {
                //you cover cell in yellow collection view
            } else {
                //you do not cover any of cells in yellow collection view
            }
    
        } else {
            //you do not cover any of collection views
        }
    }
    
于 2016-05-16T12:37:09.960 回答