Created
October 9, 2016 03:36
-
-
Save gkye/c1324c4634a143fd69b7288cd9e261bf to your computer and use it in GitHub Desktop.
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
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