Muhammad Faizan Khatri
Muhammad Faizan Khatri

Reputation: 643

Drag and Drop cell between different Collection Views

I have multiple collection views on one screen

In collectionView One i have normal cell like Square In collectionView two i have group cell e.g same cell but multiple surrounded by a border of Group

I need to Enable Drag and Drop between One Collection View to Another.

POC Snap Shot Attached here

I am using swift 3.0.

Upvotes: 9

Views: 4846

Answers (2)

shallowThought
shallowThought

Reputation: 19602

Drag from collectionView2:

  • Create an independent and drag-able instance of the cell with the same data and place it above the cell to drag
  • In Collectionview2, set the cell.isHidden = yes. This way the cell is not visible, but its empty space remains.
  • When the drag-able cell is significant dragged away from the original position, remove the original cell from the collectionView animated.

Drag to collectionView1:

When the drag-able cell is above collectionView1 and is dropped:

  • insert (animated) a cell to the target position in collectionView1 and set it hidden
  • move drag-able cell above the inserted (but hidden) cell
  • set target cell to isHidden = false
  • remove drag-able cell from superview

Upvotes: 2

Andriy Savran
Andriy Savran

Reputation: 545

You can use this one from GitHub:

https://github.com/mmick66/KDDragAndDropCollectionView

enter image description here

And here is a nice guide for it:

http://blog.karmadust.com/drag-and-drop-between-uicollectionviews/

Upvotes: 5

Related Questions