How to animate UITableView header view

前端 未结 7 1425
旧巷少年郎
旧巷少年郎 2020-12-29 09:32

I need to animate the insertion of a tableview header view. I want that the table rows to slide down while the header view expands its frame.
So far the best result I go

7条回答
  •  伪装坚强ぢ
    2020-12-29 10:23

    Here's what I got to work in Swift, with an initial frame height of zero and updating it to its full height in the animations closure:

    // Calculate new frame size for the table header
    var newFrame = tableView.tableHeaderView!.frame
    newFrame.size.height = 42
    
    // Get the reference to the header view
    let tableHeaderView = tableView.tableHeaderView
    
    // Animate the height change
    UIView.animate(withDuration: 0.6) {
        tableHeaderView.frame = newFrame
        self.tableView.tableHeaderView = tableHeaderView
    })
    

提交回复
热议问题