滑动单元格时如何隐藏其他滑动单元格操作

How do you hide other swipe cell actions when swiping the cell

我有一个具有原生 SwipeCell 功能的 tableView。 当用户轻扫单元格时,我有两个操作(删除和编辑)。 当你一直滑动单元格时,它会移动删除按钮(如预期的那样),问题是 - 背景是透明的,所以当删除按钮在编辑图标上时它看起来很糟糕。

@available(iOS 11.0, *)
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
    let deleteAction = UIContextualAction(style: .normal, title: nil) { [weak self] (action, view, complete) in

        self?.deleteAction(tableView, at: indexPath)
        complete(true)
    }
    if let cgImageX =  #imageLiteral(resourceName: "alarmDelete").cgImage {
        deleteAction.image = ImageWithoutRender(cgImage: cgImageX, scale: UIScreen.main.nativeScale, orientation: .up)
    }
    deleteAction.backgroundColor = UIColor.white.withAlphaComponent(0)

    let editAction = UIContextualAction(style: .normal, title: nil) { [weak self] (action, view, complete) in
        self?.editAction(tableView, at: indexPath)
        complete(true)
    }
    if let editImage =  #imageLiteral(resourceName: "edit").cgImage {
        editAction.image = ImageWithoutRender(cgImage: editImage, scale: UIScreen.main.nativeScale, orientation: .up)
    }
    editAction.backgroundColor = UIColor.white.withAlphaComponent(0)
    return UISwipeActionsConfiguration(actions: [deleteAction, editAction])
}

是否可以在移动单元格时隐藏其他动作?

视频:https://i.imgur.com/9betbst.mp4

谢谢

您应该按如下方式更新您的代码以解决您的问题。

let swipeActionConfig = UISwipeActionsConfiguration(actions: [deleteAction, editAction])
swipeActionConfig.performsFirstActionWithFullSwipe = false
return swipeActionConfig

但是,这将阻止第一个动作在完全滑动时执行,这意味着当滑动单元格到更多后,您将无法执行第一个动作显示。