【发布时间】:2020-01-19 15:52:08
【问题描述】:
我正在使用UIContextMenuInteraction 显示UICollectionView 的上下文菜单,如下所示:
func collectiovnView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
return UIContextMenuConfiguration(identifier: nil, previewProvider: nil, actionProvider: { _ in
let deleteAction = UIAction(title: "Delete", image: UIImage(systemName: "trash"), attributes: .destructive) { _ in
self.deleteItem(at: indexPath)
}
return UIMenu(title: "Actions", children: [deleteAction])
})
}
func deleteItem(at indexPath: IndexPath) {
self.collectionView.performBatchUpdates({
self.items.remove(at: indexPath.item)
self.collectionView.deleteItems(at: [indexPath])
})
}
一切正常,但是当我点击“删除”项目时,会出现一个奇怪的动画,其中删除的项目在其他项目移动时保持在原位,然后它立即消失。有时我什至会在新项目出现前的几分之一秒内看到空白区域或随机项目。
如果我在未显示上下文菜单的情况下调用collectionView.deleteItems(),删除动画将按预期工作。
【问题讨论】:
标签: ios swift uicollectionview uicontextmenuinteraction