最初のn 個のセルをロックしながら、UICollectionView の並べ替えのオプションを提供したいと考えています。
最初のn 個のセルが「ロック」されている (並べ替えできない) ことを示すために、背景色を明るい灰色に変更したいと考えています。
これまでのところ、セルのロックを達成することができました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
}
}
私が抱えている問題は、ロックされたセルの背景色を通常に設定できるように、ユーザーが並べ替えセルを解放したことを検出することです。
使用してみましmoveItemAt
たが、ユーザーが並べ替えをアクティブにしたときに呼び出されませんが、元のセルを元のインデックスに戻すか、並べ替えがキャンセルされた場合に呼び出されます。
使用してみましたが、そのメソッドは、ユーザーがセルを離した後ではなく、 のdidUnhighlightItemAt
直後に呼び出されます。targetIndexPathForMoveFromItemAt