我有一个带有原生 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
但是,这将阻止在完全滑动时执行第一个操作,这意味着当将单元格滑动到更多后,您将无法执行第一个操作显示。
关于ios - 滑动单元格时如何隐藏其他滑动单元格操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56990205/