自定义UITableViewCell与自定义绘图

时间:2015-10-18 01:43:49

标签: ios objective-c uitableview ios8 ios9

我有一个使用UITableViewcell的自定义子类xib。我在CAShapeLayer上有自定义边缘绘图,我在所有layoutSubviews次调用中续订了绘图。

问题是帧在iOS 8.1上正确更新,但在8.4和9.0上没有。

我错过了什么吗?

以下是自定义UITableViewCell

- (void)awakeFromNib
{
    [super awakeFromNib];

    [self.thumb.layer setBorderWidth:2.0f];
    [self.thumb.layer setBorderColor:[[AppConfiguration color2] CGColor]];
    [self.thumb.layer setCornerRadius:self.thumb.frame.size.width / 2];
    [self.thumb setClipsToBounds:YES];

    self.containerBottom.layer.shadowColor = [[UIColor r:189 g:189 b:189] CGColor];
    self.containerBottom.layer.shadowOffset = CGSizeMake(0, 1);
    self.containerBottom.layer.shadowOpacity = 1.0f;
    self.containerBottom.layer.shadowRadius = 1.0f;
}

- (void)layoutSubviews
{
    [super layoutSubviews];

    self.containerTop.backgroundColor = self.color;

    if (self.masklayer.superlayer)
        [self.masklayer removeFromSuperlayer];

    [self drawing:self.containerTop];

    [self.containerTop.layer addSublayer:self.masklayer];

    self.containerTop.layer.masksToBounds = NO;
    self.containerTop.clipsToBounds = NO;
}

+ (OperatorTableViewCell *)cell
{
    NSArray *nib = [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil];

    return [nib objectAtIndex:0];
}

- (void)drawing:(UIView *)view;
{
    CGFloat radius = 5;

    NSInteger waves = floor((view.frame.size.width / (radius * 2)));
    radius = (view.frame.size.width / waves) / 2;

    NSLog(@"Frame: %@", NSStringFromCGRect(view.frame));

    self.masklayer = [CAShapeLayer layer];

    UIBezierPath *path = [UIBezierPath bezierPath];

    CGPoint point = CGPointMake(0, view.frame.size.height - 3);

    [path moveToPoint:point];

    for (int i=0; i < (view.frame.size.width / (radius * 2)); i++)
    {
        if (i == 0)
        {
            point = CGPointMake(radius, point.y);
        }

        [path addArcWithCenter:point radius:radius startAngle:M_PI endAngle:M_PI * 2 clockwise:NO];
        point = CGPointMake(point.x + radius * 2, point.y);
    }

    self.masklayer.path = path.CGPath;
    self.masklayer.fillColor = view.backgroundColor.CGColor;
}

enter image description here

请注意,当我突出显示单元格时,会导致调用layoutSubviews并修复问题。这对我来说也很奇怪。突出显示单元格不应导致帧更改。

日志

2015-10-18 04:38:18.736 app[12905:545562] Frame: {{8, 8}, {304, 82}}
2015-10-18 04:38:18.739 app[12905:545562] Frame: {{8, 8}, {304, 82}}
2015-10-18 04:38:23.577 app[12905:545562] Frame: {{8, 8}, {359, 82}}
2015-10-18 04:38:26.936 app[12905:545562] Frame: {{8, 8}, {359, 82}}
2015-10-18 04:38:54.608 app[12905:545562] Frame: {{8, 8}, {359, 82}}
2015-10-18 04:38:54.762 app[12905:545562] Frame: {{8, 8}, {304, 82}}
2015-10-18 04:38:54.763 app[12905:545562] Frame: {{8, 8}, {304, 82}}
2015-10-18 04:38:56.258 app[12905:545562] Frame: {{8, 8}, {359, 82}}
2015-10-18 04:38:57.155 app[12905:545562] Frame: {{8, 8}, {359, 82}}

0 个答案:

没有答案