繁体   English   中英

防止 UICollectionView 交互式重新排序重新排序到某些索引路径

[英]Prevent UICollectionView interactive reordering from reordering to certain index paths

我已经构建了一个集合视图,它允许我拖动和重新排序元素。 某些元素(在我的例子中,前三个和后两个)不应重新排序,即元素 0 必须始终保留在 model 数组中的 position 0 等处。

override func collectionView(_ collectionView: UICollectionView, canMoveItemAt indexPath: IndexPath) -> Bool

这个 function 意识到了这一点,并将为这些元素返回 false。 我不能拖他们。 但是,我可以将其他元素拖到它们的位置,默认的集合视图重新排序 UI 允许这样做。

我想做的只是允许在可以移动的元素之间拖动。 不知道如何配置集合视图以阻止我拾取和拖动某些单元格。

原来我需要这个人:

override func collectionView(_ collectionView: UICollectionView, targetIndexPathForMoveFromItemAt originalIndexPath: IndexPath, toProposedIndexPath proposedIndexPath: IndexPath) -> IndexPath

在里面,我可以检查你是否打算进入那些被禁止的索引并将我想要你的地方返回到 go 代替。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM