Reputation: 41
I have a problem with implementing custom animation while swiping table view cell. The goal is to change cell background color while swipe cell with animation. Ideally, it's perfect if background color changes depending on the offset on the x-axis. Or if it's impossible or difficult to do it, it would be good to finish the animation when swiping is finished. And the background color of the cell should be the same as the action button's one. "Swiping" means gesture that makes buttons show like as default delete action.
The follow code is current one.
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let action = UIContextualAction(style: .normal, title: "", handler: { (action,view,completionHandler ) in
completionHandler(true)
})
action.image = UIGraphicsImageRenderer(size: CGSize(width: 30, height: 30)).image { _ in
UIImage(named:"sell_btn")?.draw(in: CGRect(x: 0, y: 0, width: 30, height: 30))
}
action.backgroundColor = UIColor(hex: "#F4F4F4")
tableView.backgroundColor = .red
let confrigation = UISwipeActionsConfiguration(actions: [action])
return confrigation
}
This code changes the background color when this function called.
PS: I've tried MGSwipeCell and SwipeCellKit too, but they don't provide me exact thing what I want.
Thanks.
Upvotes: 2
Views: 205