4

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.

huddie96
  • 1,240
  • 2
  • 13
  • 26
  • 1
    maybe this post can help you: https://stackoverflow.com/questions/39172207/custom-cell-reorder-behavior-in-collectionview – mugx Nov 16 '17 at 03:54
  • 1
    @AndreaMugnaini I may be wrong but this appears to be a UIViewController with a UICollectionView as a subview and a custom reorder. I'd like to use the UICollectionViewController with it's built-in methods. If this is impossible I'll switch to the VC with the collectionView as a subview. Let me know if I am mistaken – huddie96 Nov 16 '17 at 03:58

0 Answers0