Ios tableview最后一个单元格内的动画

Ios tableview最后一个单元格内的动画,ios,Ios,我有桌子视图。在单元格内我有一种方法,可以在单元格内设置视图的动画 func animateCell() { UIView.animate(withDuration: 0.4, animations: { [weak self] in self?.quantityBackround.transform = CGAffineTransform(scaleX: 25, y: 25) }) { [weak self] _ in UIView.anima

我有桌子视图。在单元格内我有一种方法,可以在单元格内设置视图的动画

func animateCell() {
    UIView.animate(withDuration: 0.4, animations: { [weak self] in
        self?.quantityBackround.transform = CGAffineTransform(scaleX: 25, y: 25)
    }) { [weak self]  _ in
        UIView.animate(withDuration: 0.1) {
            self?.quantityBackround.transform = CGAffineTransform.identity
        }
    }
}
此外,我还有准备工作()

当数据源数组发生更改时,动画必须仅对最后一个单元格有效,我在property observer中这样做(在向数组添加某些内容时激发)

所有这些都很好

我遇到的一个问题是,当重新加载tableView时,所有单元格中的所有背景视图都会从零大小扩展到初始大小。最后一个单元格的动画效果良好

我想我在准备之前错过了一些东西,正因为如此,我看到了从零到初始大小的变化


如何修复它?

您需要实现此方法的
UITableViewDelegate

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    //here check if your this cell is the last one, something like this
    if (indexPath.row == yourDataSourceArray.count - 1)
     {
         if let customCell = cell as? CheckItemTableViewCell{
           customCell.animateCell()
          }
     }
}

希望这有帮助

您只需要最后一个单元格动画?是的,只需要最后一个one@AlexeyK你能回顾一下我对你这个问题的回答吗?请给我一些反馈
guard let cell = checkTableView.cellForRow(at: IndexPath(row: viewModel.checkManager.check.count - 1, section: 0)) as? CheckItemTableViewCell else { return }
cell.animateCell()
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
    //here check if your this cell is the last one, something like this
    if (indexPath.row == yourDataSourceArray.count - 1)
     {
         if let customCell = cell as? CheckItemTableViewCell{
           customCell.animateCell()
          }
     }
}