我有一个带有本机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
谢谢
答案 0 :(得分:2)
您应按以下步骤更新代码以解决问题。
let swipeActionConfig = UISwipeActionsConfiguration(actions: [deleteAction, editAction])
swipeActionConfig.performsFirstActionWithFullSwipe = false
return swipeActionConfig
但是,这将阻止在完全滑动时执行第一个动作,这意味着在显示所有动作后将单元格滑动到更多位置时,您将无法执行第一个动作。