Skip to content
🐗Sample code illustrating how to implement a parallax scrolling table view header in Swift
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
ParallaxTableViewHeader
.gitignore
LICENSE
README.md

README.md

parallax-table-view-header

Sample code illustrating how to implement a parallax scrolling table view header in Swift

Demo

How to use

Create a new ParallaxTableHeaderView with a given size and subview as content:

var mapView = MKMapView(frame: CGRectMake(0,0, self.view.frame.width, tableHeaderViewHeight))
var tableHeaderView = ParallaxTableHeaderView(size: CGSizeMake(self.view.frame.width, tableHeaderViewHeight), subView: mapView)
tableView.tableHeaderView = tableHeaderView
tableView.delegate = self

Implement the UIScrollViewDelegate func, to layout the header view when the table view scrolls:

func scrollViewDidScroll(scrollView: UIScrollView) {
  let header: ParallaxTableHeaderView = self.tableView.tableHeaderView as! ParallaxTableHeaderView
  header.layoutForContentOffset(tableView.contentOffset)
  self.tableView.tableHeaderView = header
}
You can’t perform that action at this time.