Created
July 24, 2020 04:31
-
-
Save imnaveensharma/2356a55e251a80f947692f7f584bebce to your computer and use it in GitHub Desktop.
Scroll the header view along with the UITableView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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