-2

I'm creating a UICollectionView with reordering capabilities. A little bit like this.

I'd like to restrict the number of elements in every section of the collection view and change the "ordering animation" (while an element is dragging).

For example:
You have a collection view with 3 sections (A, B and C).
The 3 sections are with their maximum number of elements.
You move one element from section B to section A.
The last element of section A should move to section B, and not increase the number of elements in section A.

Any idea how to implement this feature?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
fleyva
  • 7
  • 1
    Asking people to write the code for you is not really what Stackoverflow is for. What have you tried until now? Post some code so we can see where you are having issues... – Mihai Fratu Jun 11 '18 at 21:13

2 Answers2

0

Some if else conditions would do and an array of current items in a sections and if the items.count are higher than the max allowed check the next section for amount of items and if lower then max drop it there.

you might want to try some Extensions like thise:

https://github.com/michel-moreau/DraggableCollectionView

https://github.com/lognllc/DraggableCollectionView

https://github.com/liangdahong/BMDragCellCollectionView

https://github.com/Instagram/IGListKit

Just be sure to download and demo their code it might be what you are looking for.

AD Progress
  • 4,190
  • 1
  • 14
  • 33
  • So there's no way to achieve this behavior by overriding a method or setting a parameter in the CollectionView right? – Cenobyte321 Jun 12 '18 at 17:50
  • without programatically checking that you are not exceeding the maxcount set no. Whilst you might be able to find an extension in the form of 3rd party library – AD Progress Jun 12 '18 at 17:56
0

Why don't you try having a function that looks at all three sections, sees which ones have too many items and then moves those. Then...When returning the number of items in each collection view, call that function when it exceeds your max number of elements for each section. Please let me know if you need clarification.

func collectionView(.....numberOfItemsOrRows?...){
    if (newArrayCountForList1 > maxElements){
        redistributeArrayValues()
     } // copy the above if statement with function inside for the next 2 arrays
 (Assuming each section has an array representing elements in that section)
}
Andy Lebowitz
  • 1,471
  • 2
  • 16
  • 23