将大于cellHeight的子视图添加到UITableViewCell?

NSS*_*Sec 15 iphone clipping uitableview

我正在尝试向UITableViewCell添加子视图,而我正在使用的设计要求这个特定的子视图(图像)需要比实际的UITableViewCell更大,因此部分重叠其兄弟.

所以我设置了我的表格单元格,生成了我的图像并将其添加到单元格的contentView中:

// rowHeight for the UITableView is 45.0f

UIImage *image = [self createCellThumbnail: someImage];
UIImageView *thumbView = [[UIImageView alloc] initWithFrame: CGRectMake(150, -5, 55,55)];
thumbView.transform = CGAffineTransformMakeRotation(0.1f);
thumbView.image = image;

cell.clipsToBounds = NO;
cell.contentView.clipsToBounds = NO;

[cell.contentView addSubview: thumbView];
Run Code Online (Sandbox Code Playgroud)

当图像"溢出"到其下方的单元格中时,图像的顶部始终被剪裁,如下所示:

IMG

有谁知道我现在的做法是否有可能做到?

或者我应该想办法在绘制完所有单元格后将这些图像绘制到UITableView上(它是一个不可滚动的tableview,这样就可以了,并且相当容易).

更新:

还尝试添加以下内容,但无济于事:

cell.opaque = NO;
cell.contentView.opaque = NO;

cell.clearsContextBeforeDrawing = NO;
cell.contentView.clearsContextBeforeDrawing = NO;

cell.clipsToBounds = NO;    
cell.contentView.clipsToBounds = NO;
Run Code Online (Sandbox Code Playgroud)

Joo*_*ost 15

我似乎tableView从下到上渲染其单元格,因此一个单元格上方的单元格与一个单元格重叠.为避免这种情况,您必须将backgroundColor所有单元格设置为,+[UIColor clearColor]以便您不会看到这些重叠问题.

但设置backgroundColor清楚-tableView:cellForRowAtIndexPath:没有任何意义.UIKit在绘制之前会对单元格做很多事情,因此它会重置backgroundColor单元格的属性.

我们需要做的是将其设置backgroundColor为稍后的状态.幸运的是-[UITableViewDelegate tableView:willDisplayCell:forRowAtIndexPath:],我们可以这样实现:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    cell.backgroundColor = [UIColor clearColor];
}
Run Code Online (Sandbox Code Playgroud)

现在我们在backgroundColor绘制单元格之前设置它,结果证明它正常工作.