【问题标题】:UITableViewCell drop shadow not drawing for some cellsUITableViewCell 阴影未为某些单元格绘制
【发布时间】:2013-04-25 01:12:33
【问题描述】:

我有一个自定义的 tableview 单元子类,它可以绘制阴影...

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

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

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

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]];

提前致谢。

【问题讨论】:

    标签: cocoa-touch uitableview core-animation


    【解决方案1】:

    看起来您正在绘制超出每个 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;
    }
    

    或者您可以实现内部阴影并避免在边界之外绘制。

    【讨论】:

      猜你喜欢
      • 2012-03-03
      • 2016-12-02
      • 2014-01-05
      • 1970-01-01
      • 2010-11-16
      • 2017-11-06
      • 1970-01-01
      • 2012-02-16
      • 1970-01-01
      相关资源
      最近更新 更多