Skip to content

Instantly share code, notes, and snippets.

@gkye
Created October 9, 2016 03:36
Show Gist options
  • Save gkye/c1324c4634a143fd69b7288cd9e261bf to your computer and use it in GitHub Desktop.
Save gkye/c1324c4634a143fd69b7288cd9e261bf to your computer and use it in GitHub Desktop.
private let kTableHeaderHeight: CGFloat = 300
var headerView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
headerView = tableView.tableHeaderView
tableView.tableHeaderView = nil
tableView.addSubview(headerView)
tableView.contentInset = UIEdgeInsets(top: kTableHeaderHeight, left: 0, bottom: 0, right: 0)
tableView.contentOffset = CGPoint(x: 0, y: -kTableHeaderHeight)
}
func updateHeaderView(){
var headerRect = CGRect(x: 0, y: -kTableHeaderHeight, width: tableView.bounds.width, height: kTableHeaderHeight)
if tableView.contentOffset.y < -kTableHeaderHeight{
headerRect.origin.y = tableView.contentOffset.y
headerRect.size.height = -tableView.contentOffset.y
}
}
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
updateHeaderView()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment