1
我想在uitableview中的所有未選定單元格上添加透明圖層。 我實現下面的代碼:lightbox在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];
}
它工作正常,但有一個例外 - 所有的座標原始細胞位置(即細胞起源仍然是相同的計算,即使用戶向下滾動,這樣的部分不能調暗的屏幕可能會被錯誤地放置如何修改代碼,以便將選中單元的實際座標考慮在內?