簡體   English   中英

不止一次動畫細胞

[英]Animating cell more than once

我有一個uitableview單元格,它會在顯示單元格時生成動畫。 這些單元格位於tableviews中,這些tableviews是uitabbarcontroller的選項卡。 但是,如果用戶第一次按下四個選項卡中的一個,則單元格將設置動畫,但如果用戶單擊新選項卡並返回上一個選項卡,則單元格將不會設置動畫。 如何在每次呈現tableview時使單元格生成動畫。 這是我的代碼,有人可以告訴我如何在每次呈現視圖時使單元格生成動畫,而不僅僅是在單元格呈現時。

override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {

        let rotationTransform = CATransform3DScale(CATransform3DIdentity, 10, 10, 0)
        cell.layer.transform = rotationTransform
        UIView.animate(withDuration: 0.6, delay: 0, usingSpringWithDamping: 0.2, initialSpringVelocity: 0.1, options: .curveEaseOut, animations: {
            cell.layer.transform = CATransform3DIdentity
        }, completion: nil)
}

重新加載視圖上的數據會出現控制器方法:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    tableview.reloadData()
}

此外,您可能需要在再次設置動畫之前重置為開始狀態。 為什么? 因為當您滾動表格視圖時,出現的單元格將不會生成動畫。 它們將在動畫之后具有最終狀態(可重復使用的單元格)。

在完成動畫之前,你可能會晃動的另一件事就是頂部單元格會消失。 我不確定會發生什么。 也許它不會采取最終狀態。 當你回到它或那個單元格被重用時,那個單元格將沒有最終狀態。 但是,如果在重新開始動畫之前重置為第一個狀態,將解決所有問題。

重置動畫:

cell.layer.transform = nil
// you may need to layout the cell. not sure. after this.
// then the rest of your code that animates the cell.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM