最近在研究collection view。我需要让一些单元格固定在它们自己的索引路径中,这意味着它们不应该被其他单元格交换并且不被拖动。我现在可以使用 *- (BOOL)collectionView:(UICollectionView *)collectionView canMoveItemAtIndexPath:(NSIndexPath )indexPath 来防止它们被拖动。我无法阻止它们被其他细胞交换。
有人遇到同样的问题吗?
谢谢
最佳答案
func collectionView(_ collectionView: UICollectionView, targetIndexPathForMoveFromItemAt originalIndexPath: IndexPath, toProposedIndexPath proposedIndexPath: IndexPath) -> IndexPath {
if proposedIndexPath.row == data.count {
return IndexPath(row: proposedIndexPath.row - 1, section: proposedIndexPath.section)
} else {
return proposedIndexPath
}
}
关于ios - UICollectionView,如何防止移动一个单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47528344/