Created
June 17, 2016 06:30
-
-
Save k3zi/73262e8a30710a7a96fe329ff1c1052e to your computer and use it in GitHub Desktop.
Masks any cells behind the section header of a .Plain 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
override func scrollViewDidScroll(scrollView: UIScrollView) { | |
super.scrollViewDidScroll(scrollView) | |
for cell in self.tableView.visibleCells { | |
let hiddenFrameHeight = scrollView.contentOffset.y + self.tableView(tableView, heightForHeaderInSection: 0) - cell.frame.origin.y | |
if hiddenFrameHeight >= 0 || hiddenFrameHeight <= cell.frame.size.height { | |
self.maskCell(cell, fromTopWithMargin: hiddenFrameHeight) | |
} | |
} | |
} | |
func maskCell(cell: UITableViewCell, fromTopWithMargin margin: CGFloat) { | |
cell.layer.mask = visibilityMaskForCell(cell, withLocation: margin/cell.frame.size.height) | |
cell.layer.masksToBounds = true | |
} | |
func visibilityMaskForCell(cell: UITableViewCell, withLocation location: CGFloat) -> CAGradientLayer { | |
let mask = CAGradientLayer() | |
mask.frame = cell.bounds | |
mask.colors = [RGB(255, a: 0.0).CGColor, RGB(255, a: 1.0).CGColor] | |
mask.locations = [NSNumber(float: Float(location)), NSNumber(float: Float(location))] | |
return mask | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment