Cocoa touch UITableViewCell阴影不绘制某些单元格

Cocoa touch UITableViewCell阴影不绘制某些单元格,cocoa-touch,uitableview,core-animation,Cocoa Touch,Uitableview,Core Animation,我有一个自定义的tableview单元格子类,它绘制一个阴影。。。 当我向下滚动时,一些单元格没有绘制阴影 当我向上滚动时也会发生这种情况 我已经尝试将绘图代码移动到单元格子类drawRect、setNeedsLayout。我也在tableviewController的配置单元格方法中尝试过这一点 self.layer.shadowRadius = 4.1f; self.layer.shadowOpacity = 0.5; self.layer.shadowOffset = CGSizeMa

我有一个自定义的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]];

提前感谢。

看起来您在每个UITableView单元格视图的边界之外绘制阴影,当UITableView重用单元格并显示它们时,可能无法使所有单元格子视图完美地堆叠在一起,您需要自己确保它们

在UITableView委托中

- (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;
}
或者,您可以实现内部阴影,避免在边界之外绘制