本文介绍了如何重叠UITableViewCells?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果你看一下截图,你会注意到每个UITableViewCell从顶部到上部tableview单元重叠20%。

If you look at the screenshot you will notice that each UITableViewCell are 20% overlapped from top portion to the upper tableview cell.

我们有什么方法可以重叠单元格吗?

Is there any way we can overlap cells ?

推荐答案

我从未尝试过,但这种逻辑可行。请记住,您不会在重叠区域中进行任何触摸。

I never tried it, but this kind of logic will work. Remember, you won't get any touch in the overlapped area.

1)将您的子视图添加到 cell.contentView ,确保子视图高度大于tableView的 rowHeight

1) Add your subview to cell.contentView, make sure subview height is greater than rowHeight of your tableView.

float overlapHeight  = 10.0;

subView.frame = CGRectMake(0.0, -10.0, 
                  your_subview_width, rowHeight + overlapHeight);

2)添加此代码,以便您的单元格不会剪切其框架之外的内容

2) Add this code, so that your cell won't clip contents outside its frame

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

3)现在你的细胞将重叠,但细胞边界周围会有一个剪辑标记。为了避免这个实现,willDisplayCell委托函数

3) Now your cell's will overlap, but there will be a clip mark around the borders of the cell. To avoid that implement willDisplayCell delegate function

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

这篇关于如何重叠UITableViewCells?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 19:00