emoji 表情过多导致cell 滑动卡顿的解决办法







使用YYText 

https://github.com/ibireme/YYText


在数据请求Controller中引入头文件


数据处理时 提前计算好每个cell的高度

    for (NSDictionary *listDicin listArray) {

                    NSDictionary *dicNUll = [[NSDictionarydictionary] dictionaryIsNSNull:listDic];

                    GJReviewsModel *reviewsModel = [GJReviewsModelcustomInitWithDictionary:dicNUll];

                    

                    NSString *commentstr = reviewsModel.comment;

                    NSMutableAttributedString *text = [NSMutableAttributedStringnew];

                    [text appendAttributedString:[[NSAttributedStringalloc] initWithString:commentstrattributes:nil]];

                    YYTextContainer *container = [YYTextContainercontainerWithSize:CGSizeMake(Width-kCustomWidth_(85)<评论内容Label宽>,MAXFLOAT)];

                    YYTextLayout *textLayout = [YYTextLayoutlayoutWithContainer:container text:text];

                    reviewsModel.textLayout = textLayout;

                    reviewsModel.cellHeight = textLayout.textBoundingSize.height+kCustomHeight_(45)<45是昵称时间Label占的高度>;

                    [weakself.pingLunArray addObject:reviewsModel];

                }




注意:GJReviewsModel 中  引入

#import "YYLabel.h"

要提前添加


@property (nonatomic,strong)YYTextLayout *textLayout;

@property (nonatomic)CGFloat cellHeight;




cell 中 懒加载创建 评论Label

[self.contentViewaddSubview:self.shipLabel];



-(YYLabel *)shipLabel

{

    if (_shipLabel ==nil) {

        _shipLabel = [[YYLabelalloc] initWithFrame:CGRectMake(kCustomWidth_(75),kCustomHeight_(45), Width-kCustomWidth_(85), 0)];

        _shipLabel.userInteractionEnabled =NO;

        _shipLabel.numberOfLines = 0;

        _shipLabel.font =FontWithSize(13);

        _shipLabel.displaysAsynchronously =YES; /// enable async display

        _shipLabel.textVerticalAlignment =YYTextVerticalAlignmentCenter;

        [_shipLabelsetBackgroundColor:[UIColorwhiteColor]];

    }

    return_shipLabel;

}




-(void)setReviewsModel:(GJReviewsModel *)reviewsModel{

    /// 头像

    if ([reviewsModel.headImgUrlisKindOfClass:[NSStringclass]]) {

        [self.headerImageViewsd_setImageWithURL:[NSURLURLWithString:reviewsModel.headImgUrl]placeholderImage:[UIImageimageNamed:@"默认头像"]];

    }

   /// 昵称

    [self.nameLabel setText:reviewsModel.createUser];

   /// 时间

    NSString *string = [NSString stringWithFormat:@"%@",reviewsModel.createTime];

    NSString *dateString = [NSDate getTimeStrByTimeSp:string format:@"yyyy/MM/dd"];

    [self.dateLabel setText:dateString];

   /// 评论

        YYTextLayout *layout = reviewsModel.textLayout;

        self.shipLabel.textLayout = layout;        

        self.shipLabel.frame = CGRectMake(kCustomWidth_(75),kCustomHeight_(45), Width-kCustomWidth_(85), layout.textBoundingSize.height);

        

  

    

}









猜你喜欢

转载自blog.csdn.net/flg1554112450/article/details/80106814