Objective c UiView上的UIBezierPath不';在滚动tableview之前,请不要更新
我已将UIView添加到Tableview的单元格中,并通过以下方式给出底部和右侧的beizer路径: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,
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
}