【发布时间】:2020-08-10 18:39:23
【问题描述】:
我正在将 iOS13 上下文菜单添加到我的表格视图中。菜单操作之一允许用户删除项目:
override func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? {
return UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { suggestedActions in
let deleteAction = UIAction(title: "Delete", image: UIImage(systemName: "trash.fill"), identifier: nil, discoverabilityTitle: "", attributes: UIMenuElement.Attributes.destructive) { action in
self.data.remove(at: indexPath.row)
//Remove from the table.
self.tableView.deleteRows(at: [indexPath], with: .automatic)
}
return UIMenu(title: "", children: [deleteAction])
}
}
我正在使用默认的预览视图控制器(所以它只显示单元格)。我目前看到一个奇怪的动画工件,其中显示上下文菜单预览,而被删除的行下方的项目动画起来,然后预览消失为白色(所以看起来列表中有一个空白行),然后该表重新绘制并显示被掩盖的项目。
这是使用默认单元格,但在使用包含更多信息的自定义单元格时看起来更糟。有没有办法让这个动作的动画效果更好?
【问题讨论】: