Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save imnaveensharma/2356a55e251a80f947692f7f584bebce to your computer and use it in GitHub Desktop.
Save imnaveensharma/2356a55e251a80f947692f7f584bebce to your computer and use it in GitHub Desktop.
Scroll the header view along with the UITableView
extension ViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
guard let tableView = scrollView as? UITableView,
let visible = tableView.indexPathsForVisibleRows,
let first = visible.first else {
return
}
let headerHeight = tableView.rectForHeader(inSection: first.section).size.height
let offset = max(min(0, -tableView.contentOffset.y), -headerHeight)
self.tblView.contentInset = UIEdgeInsets(top: offset, left: 0, bottom: -offset, right: 0)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment