I am making a UICollectionView with iOS 9's cool reorder feature. I can make a cell unmovable by returning No in the datasource's function - (BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath *)indexPath
for that index path.
However, I found the cell is able to be replaced with movable items, which is not expected.
For example,
We cannot move the 3rd item (screenshot).
But it is able to be the destination index path for other cell to move to(screenshot).
any good ideas for the 3rd cell to be really fixed?
Assume item at indexpath = {x,y} cannot be moved. Try use following delegate method.
collectionView(_:targetIndexPathForMoveFromItemAtIndexPath:toProposedIndexPath:)
If the proposed index path is equal to {x,y}
then you provide desired index path for the item. Ex {x+1,y}
From the docs:
During the interactive moving of an item, the collection view calls this method to see if you want to provide a different index path than the proposed path. You might use this method to prevent the user from dropping the item in an invalid location. For example, you might prevent the user from dropping the item in a specific section.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With