Ich verblasse Zellen meines uitableview, während sie aus der Sicht hinausrollen, oder verblassen sie, während sie in Sicht scrollen. Das Problem, mit dem ich konfrontiert bin, ist, dass, wenn ich sehr schnell scrolle, die Zellen, die vollständig sichtbar sind, abgeblendet bleiben. Hier ist mein Code unten:ios uitableview blendet untere Zelle und obere Zelle aus, während Sie blättern
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
// Fades out top and bottom cells in table view as they leave the screen
NSArray *visibleCells = [self.tableView visibleCells];
if (visibleCells != nil && [visibleCells count] != 0) { // Don't do anything for empty table view
/* Get top and bottom cells */
UITableViewCell *topCell = [visibleCells objectAtIndex:0];
UITableViewCell *bottomCell = [visibleCells lastObject];
/* Make sure other cells stay opaque */
// Avoids issues with skipped method calls during rapid scrolling
for (UITableViewCell *cell in visibleCells) {
cell.contentView.alpha = 1.0;
}
/* Set necessary constants */
NSInteger cellHeight = topCell.frame.size.height - 1; // -1 To allow for typical separator line height
NSInteger tableViewTopPosition = self.tableView.frame.origin.y;
NSInteger tableViewBottomPosition = self.tableView.frame.origin.y + self.tableView.frame.size.height;
/* Get content offset to set opacity */
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);
/* Set opacity based on amount of cell that is outside of view */
CGFloat modifier = 1.2; /* Increases the speed of fading (1.0 for fully transparent when the cell is entirely off the screen,
2.0 for fully transparent when the cell is half off the screen, etc) */
CGFloat topCellOpacity = (1.0f - ((tableViewTopPosition - topCellPosition)/cellHeight) * modifier);
CGFloat bottomCellOpacity = (1.0f - ((bottomCellPosition - tableViewBottomPosition)/cellHeight) * modifier);
/* Set cell opacity */
if (topCell) {
topCell.alpha = topCellOpacity;
}
if (bottomCell) {
bottomCell.alpha = bottomCellOpacity;
}
}
}
Jede Idee, warum, wenn ich scrollen wirklich schnell die Zellen im Auge manchmal verdunkelt bleiben?
das scheint das Problem nicht mehr zu verursachen ... aber ich bin verwirrt, wie die for-Schleife in meinem Code dies nicht behandelt. Wenn Sie schauen, habe ich diese for-Schleife in meinem Code oben: 'für (UITableViewCell * Zelle in visibleCells) { cell.contentView.alpha = 1.0; } ' –
@AtulBhatia Oh, ich war mir nicht sicher, was Sie dort zu tun versuchten. Das liegt daran, dass Sie 'cell.contentView.alpha' und nicht' cell.alpha' einstellen. Wenn du abdunkelst, änderst du 'cell.alpha', also musst du das selbe machen, wenn du es dimmst. (Und Sie wollen definitiv 'cell.alpha' für den Fall verwenden, dass Sie jemals Enthüllungsindikatoren, Zellenschattierungen usw. verwenden). Ich habe meine Antwort aktualisiert. – Rob
ah ja, dummer Fehler meinerseits. Danke, dass du mir geholfen hast! –