Skip to content

Instantly share code, notes, and snippets.

@meyusufdemirci
Created November 27, 2017 18:03
Show Gist options
  • Save meyusufdemirci/e21d4c615f6452644e6c00e4afdb4474 to your computer and use it in GitHub Desktop.
Save meyusufdemirci/e21d4c615f6452644e6c00e4afdb4474 to your computer and use it in GitHub Desktop.
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
// MARK: Outlets
@IBOutlet weak var table: UITableView!
// MARK: Properties
var navigationView = UIView()
override func viewDidLoad() {
super.viewDidLoad()
table.delegate = self
table.dataSource = self
let headerView = Bundle.main.loadNibNamed("MyHeaderView", owner: nil, options: nil)?.first as! MyHeaderView
table.stickyHeader.view = headerView
table.stickyHeader.height = headerView.frame.height
table.stickyHeader.minimumHeight = 64
navigationView.frame = CGRect(x: 0, y: 0, width: headerView.frame.width, height: headerView.frame.height)
navigationView.backgroundColor = .green
navigationView.alpha = 0
table.stickyHeader.view = navigationView
}
// MARK: Tableview
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 20
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 44
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
return tableView.dequeueReusableCell(withIdentifier: "tableCell")!
}
// MARK: Scrollview
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let offset = scrollView.contentOffset.y
let changeStartOffset: CGFloat = -180
let changeSpeed: CGFloat = 100
navigationView.alpha = min(1.0, (offset - changeStartOffset) / changeSpeed)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment