lukescott / DraggableCollectionView

Extension for the UICollectionView and UICollectionViewLayout that allows a user to move items with drag and drop. --- HELP WANTED --- Looking for maintainer and help with the experimental branch.
MIT License
549 stars 175 forks source link

Multiple selection drag and drop #9

Closed ubercolin closed 11 years ago

ubercolin commented 11 years ago

I have an implementation of a multiple item grid selection drag and drop (i.e. with an Edit mode where you tap on multiple items and then initiate the drag) that I've done with a framework for iOS5 and am in the process of converting it to work with UICollectionViews.

I'm tempted to extend DraggableCollectionView to handle this, but am wondering if you've had any thoughts about this? It seems like the biggest barrier is a portion would have to be handled in the data source, in that you would actually be changing the count of the number of items in the set during the drag (i.e. remove all but one of the selected items from the set, leaving the last one as the hidden element).

Anyway, just curious if this is something you've thought about and whether you'd be interested in seeing if we could make DraggableCollectionView handle this?

lukescott commented 11 years ago

You wouldn't have to change the data source. The code you want to look at is in LSCollectionViewLayoutHelper.m. This works by incrementing / decrementing the item of NSIndexPath.

To be honest I'm not sure how you would implement this UI wise. I'd have to see a demo of what you did in iOS 5 to really comment further.

ubercolin commented 11 years ago

I made a video that shows a little bit of what I had been doing: https://www.dropbox.com/s/ypyni07xwv9x68b/MultiItemDrag.mov

The basic flow here is:

What you suggested is the path I was pursuing, but the sticking point (in my mind) is that I've actually removed items from the set for the drag, so unless the data source can properly report the numberOfItemsInSection, this won't work (the system will be asking for more items than you can actually provide).

Hopefully I'm just missing something obvious about how the helper is translating, but it seems like the existing model is based on the actual count of items not changing.

lukescott commented 11 years ago

That is definitely complicated. What LSCollectionViewLayoutHelper does it it changes the index paths of the UICollectionViewLayoutAttributes's to make them move. You just have to make sure there isn't an NSIndexPath that doesn't exist (otherwise UICollectionView throws an exception). The physical positions are just traded around.

In order to do what you want you'd have to have the missing cells end up at the end of the section and hide them. I'm not sure if you could get it to animate properly doing it that way though.

lukescott commented 11 years ago

For now this isn't something I'm able to do.

ubercolin commented 11 years ago

Agreed. If I have time, I'll take a crack at it; it'll either need to have a subclass of the data source or hijack the datasource during dragging.