I want to provide the option of UICollectionView reordering while locking the first n cells.
In order to denote that the first n cells are "locked" (cannot be reordered) I want to change their background colors to a light gray.
So far I've been able to achieve the cell locking through targetIndexPathForMoveFromItemAt
override func collectionView(_ collectionView: UICollectionView, targetIndexPathForMoveFromItemAt originalIndexPath: IndexPath, toProposedIndexPath proposedIndexPath: IndexPath) -> IndexPath {
// Gray out illegal moves
for i in lockedIndex_start...lockedIndex_end {
collectionView.cellForItem(at: IndexPath(item: i, section: 0))?.backgroundColor = UIColor.groupTableViewBackground
}
/* Check if user made an illegal move
If Yes:
Switch back
Else:
Update users personal order
*/
if proposedIndexPath.item > lockedIndex_end {
return proposedIndexPath
}else{
return originalIndexPath
}
}
The problem I'm having is detecting when the user releases the reorder cell so that I can set the background colors of the locked cells to normal.
I've tried using moveItemAt
but that doesn't get called when the user activates reordering but ends up placing the original cell back in its original index or if the reorder gets canceled.
I've tried using didUnhighlightItemAt
but that method gets called right after targetIndexPathForMoveFromItemAt
, not after the user releases the cell.