UITableViewCell自动布局宽度不适用于UIBezierPath

sky*_*rew 6 objective-c uitableview ios autolayout

使用UIBezierPath时,UITableViewCell中的自动布局约束存在问题.我的细胞不会全宽.您可以看到图像1和图像2之间的不同.图像2我没有添加圆角.

图片1 使用UIBezierPath

图2 没有UIBezierPath

以前,我在UiView中遇到了与UIBezierPath相同的问题(你可以看到前面的2个UIView为"0").我正在使用的解决方法是屏蔽viewDidLayoutSubviews中的圆角,如下面的代码: -

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    [self.view layoutIfNeeded];

    UIView *container =  (UIView *)[self.view viewWithTag:100101];
    [container setBackgroundColor:[UIColor colorWithHexString:@"ffffff"]];
    [self setMaskTo:container byRoundingCorners:UIRectCornerAllCorners];
}
Run Code Online (Sandbox Code Playgroud)

但现在我陷入了UITableViewCell,因为我无法在viewDidLayoutSubviews中添加舍入角.我的代码如下: -

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"myData";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    MyWClass *w = [_wData objectAtIndex:indexPath.row];

    UIView *container = (UIView *) [cell viewWithTag:200001];
    [container setBackgroundColor:[UIColor colorWithHexString:w.bgColor]];
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:container.layer.bounds
                                                   byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
                                                         cornerRadii:CGSizeMake(10.0, 10.0)];
    CAShapeLayer *maskLayer = [CAShapeLayer layer];
    maskLayer.frame = container.bounds;
    maskLayer.path = maskPath.CGPath;
    container.layer.mask = maskLayer;

    [cell setBackgroundColor:[UIColor colorWithHexString:@"#efeff4"]];
    cell.layer.masksToBounds = NO;
    cell.layer.shadowOpacity = 1.0;
    cell.layer.shadowOffset = CGSizeMake(0, 2);
    cell.layer.shadowColor = [UIColor colorWithHexString:@"#e4e4e8"].CGColor;
    cell.layer.shadowRadius = 0;

    return cell;
}
Run Code Online (Sandbox Code Playgroud)

我尝试添加[cell.contentView layoutIfNeeded];但仍然相同.

任何帮助,将不胜感激.

Ven*_*h G 0

以下逻辑对我有用:

将 UIview 宽度设置为单元格宽度。

前任:container.frame.size.width = cell.frame.size.width