How to animate UITableView header view

前端 未结 7 1499
旧巷少年郎
旧巷少年郎 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:13

    Use below code this works

    extension UITableView {
    
     func hideTableHeaderView() -> Void {
        self.beginUpdates()
        UIView.animate(withDuration: 0.2, animations: {
            self.tableHeaderView = nil
        })
        self.endUpdates()
    }
    
    func showTableHeaderView(header: UIView) -> Void {
        let headerView = header
        self.beginUpdates()
        let headerFrame = headerView.frame
        headerView.frame = CGRect()
        self.tableHeaderView = headerView
        UIView.animate(withDuration: 0.2, animations: {
            self.tableHeaderView?.frame = headerFrame
            self.tableHeaderView?.alpha = 0
            self.endUpdates()
        }, completion: { (ok) in
            self.tableHeaderView?.alpha = 1
        })
       }
    }
    

提交回复
热议问题