Skip to content

Instantly share code, notes, and snippets.

@imnaveensharma
Created November 8, 2020 07:24
Show Gist options
  • Save imnaveensharma/81d113f5d2384d844afd509cd18e6349 to your computer and use it in GitHub Desktop.
Save imnaveensharma/81d113f5d2384d844afd509cd18e6349 to your computer and use it in GitHub Desktop.
Scroll table view header with table scroll
// MARK: - Extension :: UIScrollViewDelegate ::
extension ViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
//--- Scroll Table Header with Table Scroll ---//
if let tableView = scrollView as? UITableView {
if let visible = tableView.indexPathsForVisibleRows {
if let first = visible.first {
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