2017-08-15 49 views
1

我有桌面视图。在单元格内部,我有方法在单元格内动画查看。桌面视图的最后一个单元格内的动画

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 
     } 
    } 
} 

我也有prepareForReuse()

override func prepareForReuse() { 
    quantityBackround.transform = CGAffineTransform.identity 
    } 

动画只能当数据源改变阵列和我做这个物业观察者像这样(火灾时,东西被添加到工作的最后一个单元格array)

guard let cell = checkTableView.cellForRow(at: IndexPath(row: viewModel.checkManager.check.count - 1, section: 0)) as? CheckItemTableViewCell else { return } 
cell.animateCell() 

所有这些工作正常。

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

我认为我错过了prepareForReuse中的一些东西,并且因为这个,我看到了这个从零到初始大小的小问题。

如何解决?

+0

你只需要在最后一个单元格动画的这种方法吗? –

+0

是的,只有最后一个 –

回答

1

您需要实现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() 
      } 
    } 
} 

希望这有助于

+0

只是工作很好。非常感谢! –

+0

@AlexeyK你可以在这个问题上回顾我的回答吗? https://stackoverflow.com/questions/45592182/core-animation-modify-animation-property/45595503#45595503请给我一些反馈 –

相关问题