0


I followed the tutorial of Brian Advent https://www.youtube.com/watch?v=FpTY04efWC0 to animate my TableView but his animation works only on cell, how can i do the same animation on 3 sections headers ?

This is the animation on cell

func Animation(){
    TableViewContent.reloadData()
    let cells = TableViewContent.visibleCells

    let TableViewHeight = TableViewContent.bounds.size.height

    for cell in cells{
        cell.transform = CGAffineTransform(translationX: 0, y:TableViewHeight )
    }

    var delayCounter = 0.0
    for cell in cells{
        UIView.animate(withDuration: 1.75, delay: delayCounter * 0.05, usingSpringWithDamping: 0.8, initialSpringVelocity: 0, options: .curveEaseInOut, animations: {
        cell.transform = CGAffineTransform.identity}, completion: nil)
        delayCounter += 1
    }
}
Rombond
  • 129
  • 2
  • 11

1 Answers1

1

Well this is possible but it's tricky and needs extra operations.

The way your animation works is that it gets all visible cell on the current window, loop through each of them and then apply animation for each of them. Your header is nothing special, it's like a normal cell, they are all just views. So all you need to do here is to add the header to correct position in your cells array and then simply loop through them and do the animation.

After getting all the cells, loop through them and check which section are they in. Say you find out that they are from section 0, 1 and 2. Then you need to get cells for these three section by calling this

let header = tableView.headerViewForSection(section: index) as! HeaderView

Then you need to add these sections to the corresponding place in your cell array. So your cell array will finally look like

header0 - cell0 - cell1 - cell2 - header1 - cell0 - cell1 - header2 - cell0

Finally, run the rest of your code to loop through them and apply animation one by one.

Fangming
  • 24,551
  • 6
  • 100
  • 90