I have a tableview. The tableview cell contains images, labels. In this cell I have a button to delete the row. I want to animate the cell during deletion(ex. tinder like left or right swipe) or any animation to make the app actractive. How to do this type of animation. Or any recommended library?
UITableViewCellEditingStyle
will do the job for you for ie
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
//do your necessary operations here
//reload your UITableView here
}
}
Swipe right to left to see the animation.
Typical Animation for your case:
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
// your code
tableView.deleteRows(at: [indexPath], with: .automatic)
// your code
}
}
Alternate Way for custom Animation (Updated) :
tableView.beginUpdates()
tableView.deleteRows(at: [indexPath], with: .top) // Check (.)after for available animation example comment out below -
//tableView.deleteRowsAtIndexPaths([YourIndexPathYouWantToDeleteFrom], with: .left)
//tableView.deleteRowsAtIndexPaths([YourIndexPathYouWantToDeleteFrom], with: .right)
//tableView.deleteRowsAtIndexPaths([YourIndexPathYouWantToDeleteFrom], with: .up)
//tableView.deleteRowsAtIndexPaths([YourIndexPathYouWantToDeleteFrom], with: .down)
//tableView.deleteRowsAtIndexPaths([YourIndexPathYouWantToDeleteFrom], with: .fade)
//tableView.deleteRowsAtIndexPaths([YourIndexPathYouWantToDeleteFrom], with: .middle)
//tableView.deleteRowsAtIndexPaths([YourIndexPathYouWantToDeleteFrom], with: .bottom)
tableView.endUpdates()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.