2017-01-23 2 views

ответ

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

So willDisplay cell/header обрабатывает анимацию снизу экрана.

shouldAnimate отменяет анимацию клеток после окончания insertSection

0

Как насчет

  • создать новую таблицу, добавить его как подвид от нижней части экрана и называют reloadData заполнить его, используя только данные для второго секции.
  • Анимация этой новой таблицы на месте, ниже существующей секции .
  • После того, как новый раздел находится на месте, перезагрузите основную таблицу всеми данными, а затем удалите вторую таблицу из ее супервизора.