我想在 uitableview 中的所有未选择的单元格上方添加透明层。我实现了以下代码:
-(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];
}
它工作正常,有一个例外 - 所有坐标都是针对原始单元格位置计算的(即,即使用户向下滚动,单元格原点也保持不变,因此不应该变暗的屏幕部分可能放置错误。怎么可能我修改代码以便考虑所选单元格的实际坐标?