2017-08-15 45 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請給我一些反饋 –

相關問題