如何删除集合视图单元格以及此行为?

2024-03-28

我正在使用以下代码。此代码只是通过淡入淡出集合视图单元格并将其下方的其余部分向上移动来删除集合视图单元格。我不确定我应该如何制作这个动画。非常感谢您的帮助。

func remove()
    {
        totalItems -= 1
        data.remove(at: itemIdValue)
        collectionView.deleteItems(at: [indexPathValue])
    }


func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
   let cell = collectionView.cellForItem(at: indexPath) as? InviteTasker1CellView
    cell.invitationSent()
    indexPathValue = indexPath
    itemIdValue = indexPath.item
    remove()
   }

也许使用表视图可以做得更好,但我不确定解决方案。

请帮助我理解你会怎么做?多谢。


UICollectionView 和 UITableView 创建一个默认动画,这是您从其中删除单元格时想要的动画。 不过,由于您只使用一列,我建议您使用 UITableView 而不是 UICollectionView。 要使用动画从表格视图中删除行,请执行以下操作:

self.yourDataSourceArray.removeValue(at: self.indexPath.row)
self.tableView?.deleteRows(at: [self.indexPath], with: UITableViewRowAnimation.automatic)

如果您仍然想使用 UICollectionView,请按以下步骤操作:

override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    self.yourDataSourceArray.remove(at: indexPath.row)
    collectionView.deleteItems(at: [indexPath])
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何删除集合视图单元格以及此行为? 的相关文章

随机推荐