如何使用 UISwipeActionsConfiguration 设置删除单元格的延迟?

How to set the delay in deleting cell with UISwipeActionsConfiguration?

我正在创建任务列表。您可以通过滑动单元格并单击滑动按钮来标记任务和完成。 .destructive 样式使单元格立即消失,这在这里看起来不太好。我想让它慢一点(可能先褪色而不是消失)。

我正在学习 Swift 但不知道如何去做,也没有在互联网上找到任何提示。谁能帮帮我?

这是我的函数:

override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
        let markAsDone = UIContextualAction(style: .destructive, title: "DONE") { (doneAction, view, isSuccess) in
            print("User marked task as done")
            isSuccess(true)
        }
        markAsDone.backgroundColor = UIColor.lightGray
        return UISwipeActionsConfiguration(actions: [markAsDone])
    }

你可以这样试试,

tableView.beginUpdates()
tableView.deleteRows(at: indexPath, with: .fade) // Use your desired indexPath
tableView.endUpdates()