[英]Animate tableview cell when deleting
我有一个表格视图。 tableview 单元格包含图像、标签。 在这个单元格中,我有一个删除该行的按钮。 我想在删除过程中为单元格设置动画(例如向左或向右滑动等火种)或任何 animation 以使应用程序变得活跃。 这种类型的 animation 怎么做。 或者有什么推荐的图书馆?
UITableViewCellEditingStyle
将为您完成工作,即
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
//do your necessary operations here
//reload your UITableView here
}
}
从右向左滑动查看 animation。
适用于您的案例的典型 Animation:
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
// your code
tableView.deleteRows(at: [indexPath], with: .automatic)
// your code
}
}
自定义 Animation 的替代方式(更新) :
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.