Frage

I need to drag a Cell from CollectionView One and drop it to CollectionView Two. The Drag & Drop inside one CollectionView is no Problem, but how can i get the Cell out of CollectionView One to CollectionView Two?

Any ideas? Any projects or frameworks that have already solved this problem? Thanks for helping!

War es hilfreich?

Lösung

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 !

Andere Tipps

When you select the cell from the first collection view, remove it from this collection view, create a new view as copy of that cell place it as subview of the superview on top of all views. Make that view movable using pan gestures. As soon as you "drop" this intermediary cell, detect its position and add it to the current collection view.

Ok, here is the simplest flow ever for the following example:

enter image description here

  1. Add UIGestureRecognizer for every of UICollectionView.
  2. Connect every gesture recognizer with one method:

    @IBAction func longPressGestureChanged(recognizer: UILongPressGestureRecognizer) { ... }
    
  3. Within UIViewController add @IBOutlet for each of UICollectionView:

    @IBOutlet var collectionViewGreen: UICollectionView!
    @IBOutlet var collectionViewYellow: UICollectionView!
    
  4. Implement gesture recognizer method to detect changes:

    @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
        }
    }
    
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top