Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c UiView上的UIBezierPath不';在滚动tableview之前,请不要更新_Objective C_Uitableview - Fatal编程技术网

Objective c UiView上的UIBezierPath不';在滚动tableview之前,请不要更新

Objective c UiView上的UIBezierPath不';在滚动tableview之前,请不要更新,objective-c,uitableview,Objective C,Uitableview,我已将UIView添加到Tableview的单元格中,并通过以下方式给出底部和右侧的beizer路径: UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, cell.bgView.frame.size.width -2+ shadowSize,

我已将UIView添加到Tableview的单元格中,并通过以下方式给出底部和右侧的beizer路径:

UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:CGRectMake(0,
                          0,
                          cell.bgView.frame.size.width -2+ shadowSize,
                          cell.bgView.frame.size.height+1 + shadowSize)];
    cell.bgView.layer.masksToBounds = NO;
    cell.bgView.layer.shadowColor = [[UIColor colorWithRed:186.0/255.0 green:0.0/255.0 blue:231.0/255.0 alpha:1.0f]CGColor];
    cell.bgView.layer.shadowOffset = CGSizeMake(0.0f, 0.0f);
    cell.bgView.layer.shadowOpacity = 0.7f;
    cell.bgView.layer.shadowPath = shadowPath.CGPath;
第一次,当tableview重新加载时,贝塞尔路径无法正确加载

但当我向上/向下滚动时,它看起来非常完美

我已经试过了所有可能的解决办法,例如:

dispatch_async(dispatch_get_main_queue(), ^{
                [self.topRatedTable reloadData];
            });


但什么都不起作用。

您的单元格及其子视图(例如,我假设,
bgView
)在运行布局之前不会有最终帧。如果创建代码的路径位于
tableView:cellforrowatinexpath:
方法中,则在运行布局之前,您正在访问
cell.bgView.frame

在自定义的
UITableViewCell
子类中,在调用
super
后覆盖
layoutSubviews
并设置
阴影路径

// In your custom `UITableViewCell` subclass:
- (void)layoutSubviews {
    [super layoutSubviews];
    UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:CGRectMake(0,
                      0,
                      cell.bgView.frame.size.width -2+ shadowSize,
                      cell.bgView.frame.size.height+1 + shadowSize)];
    self.bgView.layer.shadowPath = shadowPath.CGPath;
}
使用以下命令:

  override func draw(_ rect: CGRect) {
        super.draw(rect)
        // UIBezierPath job
    }

重写UITableViewCell的绘图函数不是很糟糕吗?
  override func draw(_ rect: CGRect) {
        super.draw(rect)
        // UIBezierPath job
    }