Reputation: 620
I have a tableView with native SwipeCell functionality. When users swipe the cell a little, I have two actions (delete & edit). When you swipe the cell all the way, it will move the delete button (as expected), the problem is - the background is transparent, so when the delete button is over the edit icon it looks bad.
@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])
}
Is it possible to hide other actions when moving the cell all the way?
Video: https://i.imgur.com/9betbst.mp4
Thanks
Upvotes: 0
Views: 544
Reputation: 3056
You should update your code as follows to fix your issue.
let swipeActionConfig = UISwipeActionsConfiguration(actions: [deleteAction, editAction])
swipeActionConfig.performsFirstActionWithFullSwipe = false
return swipeActionConfig
But, this will prevent first action perform with full swipe, means you can't able to do first action when swipe cell to more after all action display.
Upvotes: 2