Created
November 8, 2020 07:24
-
-
Save imnaveensharma/81d113f5d2384d844afd509cd18e6349 to your computer and use it in GitHub Desktop.
Scroll table view header with table scroll
This file contains 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
// 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