tableView滑动很卡的原因

最近发现项目中自己写的列表在滑动时有些卡,而同事的列表很顺畅,两个列表显示的内容基本相同,都是几个imageView和几个label还有1个按钮,功能上主要是异步加载图片.

经过分析查找,最终发现问题的根源在于图标的圆角处理方式:

我的列表的cell在处理圆角时直接使用 :
iconImageView = [[UIImageView alloc]init];

iconImageView.layer.cornerRadius = 12;

而同事处理圆角时使用CAShapeLayer处理:

@interface CollectionViewCellImageView : UIImageView

@property (nonatomic, strong) CAShapeLayer * maskLayer;
@property (nonatomic, assign) CGFloat   maskCornerRadius;
@property (nonatomic, strong) NSURL * url;

@end

@implementation CollectionViewCellImageView

- (instancetype)init
{
    self = [super init];
    if (self) {
        _maskLayer = [CAShapeLayer new];
        _maskLayer.fillColor = [UIColor whiteColor].CGColor;
        _maskLayer.fillRule = kCAFillRuleEvenOdd;
        [self.layer addSublayer:_maskLayer];
    }
    return self;
}

- (void)setMaskCornerRadius:(CGFloat)maskCornerRadius{
    _maskCornerRadius = maskCornerRadius;
    _maskLayer.borderWidth = 0.5;
    _maskLayer.borderColor = hllColor(120, 120, 120, 0.3).CGColor;
    _maskLayer.cornerRadius = maskCornerRadius;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    _maskLayer.frame = self.layer.bounds;
    UIBezierPath* path = [UIBezierPath bezierPathWithRect:self.layer.bounds];
    [path appendPath:[UIBezierPath bezierPathWithRoundedRect:self.layer.bounds cornerRadius:self.maskCornerRadius]];
    _maskLayer.path = path.CGPath;
    
}

@end


创建UIImageView的子类,使用时

iconImageView = [[CollectionViewCellImageView alloc]init];

        iconImageView.maskCornerRadius = 12.0f;


修改后,列表滑动非常流畅.



评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

老槽哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值