For those who want this, here are some ready-to-use copies / paste codes that fully work:
The best part: this code only depends on ONE external property: self.tableViewso just make sure you are set up and you're good to go!
-:
#pragma mark - Scroll View Delegate Methods
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSArray *visibleCells = [self.tableView visibleCells];
if (visibleCells != nil && [visibleCells count] != 0) {
UITableViewCell *topCell = [visibleCells objectAtIndex:0];
UITableViewCell *bottomCell = [visibleCells lastObject];
for (UITableViewCell *cell in visibleCells) {
cell.contentView.alpha = 1.0;
}
NSInteger cellHeight = topCell.frame.size.height - 1;
NSInteger tableViewTopPosition = self.tableView.frame.origin.y;
NSInteger tableViewBottomPosition = self.tableView.frame.origin.y + self.tableView.frame.size.height;
CGRect topCellPositionInTableView = [self.tableView rectForRowAtIndexPath:[self.tableView indexPathForCell:topCell]];
CGRect bottomCellPositionInTableView = [self.tableView rectForRowAtIndexPath:[self.tableView indexPathForCell:bottomCell]];
CGFloat topCellPosition = [self.tableView convertRect:topCellPositionInTableView toView:[self.tableView superview]].origin.y;
CGFloat bottomCellPosition = ([self.tableView convertRect:bottomCellPositionInTableView toView:[self.tableView superview]].origin.y + cellHeight);
CGFloat modifier = 2.5;
CGFloat topCellOpacity = (1.0f - ((tableViewTopPosition - topCellPosition) / cellHeight) * modifier);
CGFloat bottomCellOpacity = (1.0f - ((bottomCellPosition - tableViewBottomPosition) / cellHeight) * modifier);
if (topCell) {
topCell.contentView.alpha = topCellOpacity;
}
if (bottomCell) {
bottomCell.contentView.alpha = bottomCellOpacity;
}
}
}
<UIScrollViewDelegate> '.h' !
- viewDidLoad : [self scrollViewDidScroll:self.tableView];, ( ).
. none (self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;) , .
, .