2017-01-23 95 views
1

我需要在UITableView中插入部分動畫來插入部分,但我需要從屏幕底部開始動畫。如何從屏幕底部設置動畫插入部分

而不是像默認的UITableViewRowAnimation動畫之一。

這是動畫,我需要:

Animation description

有什麼建議?

感謝

回答

2

我想通過一個簡單的解決方案來做到這一點。

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

    if shouldAnimate { 
     cell.alpha = 0 
     let transform = CATransform3DTranslate(CATransform3DIdentity, 0, UIScreen.main.bounds.height, 0) 
     cell.layer.transform = transform 

     UIView.animate(withDuration: 0.5, animations: { 
      cell.alpha = 1 
      cell.layer.transform = CATransform3DIdentity 
     }) 
    } 
} 

public func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) { 
    if shouldAnimate { 
     view.alpha = 0 
     let transform = CATransform3DTranslate(CATransform3DIdentity, 0, UIScreen.main.bounds.height, 0) 
     view.layer.transform = transform 

     UIView.animate(withDuration: 0.5, animations: { 
      view.alpha = 1 
      view.layer.transform = CATransform3DIdentity 
     }) 
    } 
} 

public func addSections(sections: IndexSet) { 
    shouldAnimate = true 
    CATransaction.begin() 
    CATransaction.setCompletionBlock({ self.shouldAnimate = false }) 

    tableView.beginUpdates() 
    tableView.insertSections(sections, with: .top) 
    tableView.endUpdates() 

    tableView.scrollToRow(at: IndexPath(row: 0, section: 1), at: .top, animated: true) 

    CATransaction.commit() 
} 

所以willDisplay cell/header從屏幕底部處理動畫。

shouldAnimate取消完成後的單元格動畫insertSection

0

如何

  • 創建新表,將其添加爲一個子視圖關閉屏幕 的底部,並調用reloadData只使用數據的第二 部分來填充它。
  • 將此新表放置到位,低於現有的 部分。
  • 新部分到位後,重新載入包含所有數據的主表,然後從其超級視圖中刪除第二個表。
相關問題