UITableViewCell的阴影不拉丝一些细胞

问题描述:

我有画阴影的自定义的tableview细胞亚类... Views First LoadUITableViewCell的阴影不拉丝一些细胞

当我向下滚动,一些细胞没有他们的身影拉...当我滚动备份

enter image description here

也会发生这种情况。

我已经尝试将绘图代码移动到单元格子类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]]; 

在此先感谢。

看起来你是在每个UITableViewCell视图的边界之外绘制阴影,当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; 
} 

,或者你可以implment内阴影,避免绘制边界之外。