0

我有一个自定义的 tableview 单元子类,它绘制了一个阴影...... 浏览量首次加载

当我向下滚动时,一些单元格没有绘制阴影......

在此处输入图像描述

当我向上滚动时也会发生这种情况。

我尝试将绘图代码移动到单元格子类 drawRect、setNeedsLayout。我也在 tableviewController 的配置单元格方法中尝试过这个。

self.layer.shadowRadius = 4.1f;
self.layer.shadowOpacity = 0.5;
self.layer.shadowOffset = CGSizeMake(2.1f,7.4f);

CGFloat curlFactor = 15.00f;
CGFloat shadowDepth = 4.6f;
CGSize size = self.layer.bounds.size;

UIBezierPath* path = [UIBezierPath bezierPath];

[path moveToPoint:CGPointMake(0.0f, 0.0f)];
[path addLineToPoint:CGPointMake(size.width, 0.0f)];
[path addLineToPoint:CGPointMake(size.width, size.height + shadowDepth)];

[path addCurveToPoint:CGPointMake(0.0f, size.height + shadowDepth)
        controlPoint1:CGPointMake(size.width - curlFactor, size.height + shadowDepth - curlFactor)
        controlPoint2:CGPointMake(curlFactor, size.height + shadowDepth - curlFactor)];
[self.layer setShadowPath:[path CGPath]];

提前致谢。

4

1 回答 1

0

It looks like you are drawing shadows out of bounds of each UITableViewCell view, when UITableView is reusing cells and displaying them, it may not keep all cell subviews stacked over each other perfectly and you need to ensure them yourself.

in UITableView delegate

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    static int index = -1;
    if (indexPath.row > index) {
        [tableView sendSubviewToBack:cell];
    }
    else {
        [tableView bringSubviewToFront:cell];
    }
    index = indexPath.row;
}

or you can implment inner shadow and avoid drawing outside of bounds.

于 2013-04-29T03:20:46.380 回答