Skip to content

Instantly share code, notes, and snippets.

@NarendraPunchh
Last active February 22, 2017 09:30
Show Gist options
  • Save NarendraPunchh/d1aa6d00b5331c49093e5926ddb12b37 to your computer and use it in GitHub Desktop.
Save NarendraPunchh/d1aa6d00b5331c49093e5926ddb12b37 to your computer and use it in GitHub Desktop.
This will help us in creating a clear section header. As right now the simple solution is to use a solid color in place of clear background so the content is not visible behind header.
#define Header_height 30
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
for (UITableViewCell *cell in self.tblRedeemables.visibleCells) {
CGFloat hiddenFrameHeight = scrollView.contentOffset.y + Header_height - cell.frame.origin.y;
if (hiddenFrameHeight >= 0 || hiddenFrameHeight <= cell.frame.size.height) {
[self maskCell:cell
fromTopWithMargin:hiddenFrameHeight];
}
}
}
- (void)maskCell:(UITableViewCell *)cell fromTopWithMargin:(CGFloat)margin {
cell.layer.mask = [self visibilityMaskForCell:cell withLocation:margin/cell.frame.size.height];
cell.layer.masksToBounds = YES;
}
- (CAGradientLayer *)visibilityMaskForCell:(UITableViewCell *)cell withLocation:(CGFloat)location {
CAGradientLayer *mask = [CAGradientLayer layer];
mask.frame = cell.bounds;
mask.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithWhite:1 alpha:0] CGColor], (id)[[UIColor colorWithWhite:1 alpha:1] CGColor], nil];
mask.locations = [NSArray arrayWithObjects:[NSNumber numberWithFloat:location], [NSNumber numberWithFloat:location], nil];
return mask;
}
@NarendraPunchh
Copy link
Author

screen shot 2017-02-03 at 10 43 34 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment