Open platapus94 opened 11 years ago
under the method modifiedLayoutAttributesForElements in the helper LSCollectionViewLayoutHelper under the logical statements if(indexPath.item <= fromIndexPath.item && indexPath.item > toIndexPath.item) and else if(indexPath.item >= fromIndexPath.item && indexPath.item < toIndexPath.item)
, if you switch the layoutAttributes.indexPath variable to
layoutAttributes.indexPath = [NSIndexPath indexPathForItem:toIndexPath.item inSection:indexPath.section]; where you specify toIndexPath.item, while you're holding the cell, it appears to have switch properly, but upon releasing, the cell you switched out gets moved to a previous index.
How can I keep this from happening?
I'm not entirely clear on what you're trying to do. The way DraggableCollectionView currently works is it exchanges index paths of what is visible.
I do have a rewrite coming down the pipe that works quite differently. It allows you to hide any number of items and place a placeholder at any index, while the layout itself is being computed. I'm not sure if that will be of any help.
I have a DraggableCollectionView instantiated with 6 objects. Picture A Collection View with 3 rows and 2 columns, so theres 2 cell's in each row. If I were to switch the cell's of a row (like exchange cell at index 0 with index 1), they change fine. However, if I switch cell at index 1, with index 5 (the cell on the first row, 2nd column, with the cell at the 3rd row 2nd column) instead of switching each, it moves the cell that USED to be at index 1, to index 2 (the first cell in the next row)
I'm trying to have them switch at each spot instead of moving the cells one index forward...does that make sense or should I try explaining it differently? (I'm sorry, this is really the first time I'm seeking help)
It seems like, despite what is shown on the layout, the array is computed differently and returned upon the ending of the warping process.
I understand what you're saying. You simply want to swap the two cells. That's not generally how drag and drop works. Drag and drop is more of remove then insert function, hence the re-ordering. You could "swap" them in two steps by doing two drags.
Would that work for larger collections however? What if I have 5 rows and 4 columns? Would I have to perform more drags?
If this is what it'll take to make the switch (and let me first thank you very much, not only for this library but also for your help), which method would I specifically call to try and get this drag done?
Judging by where the remove/insert function is, I'm guessing I'd probably do this under moveItemAtIndexPath method of my collection's view controller
never mind I got it working, thank you very much for your insight!
platapus94, I'd like to do the same thing. Can you share your modifications to allow simple swapping of cells?
I'm trying to alter the LSCollectionViewLayoutHelper file to allow me to simply exchange position of the cells without altering the position's of the other cells. For example, I drag a cell from the 3rd row 2nd column, to the 2nd row 2nd column, then instead of switching position's, the cell in the 2nd row 2nd column gets pushed down to the 3rd row 1st column.
How would I be able to prevent this? Any help would be greatly appreciated!