I would like to add transparent layers above all unselected cells in a uitableview. I implemented the following code:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
customCell *selectedCell = (customCell*)[tableView cellForRowAtIndexPath:indexPath];
overlayAboveSelectedCell = [[UIView alloc] initWithFrame:CGRectMake(listViewTable.frameOrigin.x, listViewTable.frame.origin.y, listViewTable.frameWidth, selectedCell.frameOrigin.y)];
overlayAboveSelectedCell.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
[self.view insertSubview:overlayAboveSelectedCell aboveSubview:listViewTable];
overlayBellowSelectedCell = [[UIView alloc] initWithFrame:CGRectMake(listViewTable.frameOrigin.x, selectedCell.frameOrigin.y+selectedCell.frameHeight, listViewTable.frameWidth, listViewTable.frameHeight-selectedCell.frameOrigin.y-selectedCell.frameHeight)];
overlayBellowSelectedCell.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5];
[self.view insertSubview:overlayBellowSelectedCell aboveSubview:listViewTable];
listViewTable.scrollEnabled = NO;
[selectedCell doSomething];
}
It works fine with one exception - all the coordinates are calculated for the original cell position (i.e. cell origin remains the same even when the user scrolls down, so the part of the screen that shouldn't be dimmed might be placed wrongly. How could I modify the code so that the actual coordinates of selected cell would be taken into consideration?