• Stars
    star
    114
  • Rank 308,031 (Top 7 %)
  • Language
    Objective-C
  • Created about 8 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

仿赤兔、新浪微博动态列表(带评论、点赞、转发和分享,自动计算行高功能)

HKPTimeLine

description

MyCSDN: iOS-仿赤兔、新浪微博动态列表(带评论、点赞、转发和分享,自动计算行高功能)
项目中使用到的第三方框架有:Masonry,HYBMasonryAutoCellHeight,SDWebImage

文件结构:

pic1

数据源:

项目中的数据来源不是来自公司服务器,是通过函数随机产生。以下这部分代码大家可以在实际开发中通过后台服务器获取的数据代替。

- (void)randomModel:(YHWorkGroup *)model totalCount:(int)totalCount{
    model.type = arc4random()%totalCount %2? DynType_Forward:DynType_Original;
    if (model.type == DynType_Forward) {
        model.forwardModel = [YHWorkGroup new];
        [self creatOriModel:model.forwardModel totalCount:totalCount];
    }
    [self creatOriModel:model totalCount:totalCount];  
}

使用Masorny布局时要打开符号断点:
pic3

行高计算:

取缓存高度,若为0,则计算高度。

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row < self.dataArray.count) {
        CGFloat height = 0.0;
        //原创cell
        Class currentClass  = [CellForWorkGroup class];
        YHWorkGroup *model  = self.dataArray[indexPath.row];
        
        //取缓存高度
        NSDictionary *dict =  self.heightDict[model.dynamicId];
        if (dict) {
            if (model.isOpening) {
                height = [dict[@"open"] floatValue];
            }else{
                height = [dict[@"normal"] floatValue];
            }
            if (height) {
                return height;
            }
        }
        
        //转发cell
        if (model.type == DynType_Forward) {
            currentClass = [CellForWorkGroupRepost class];//第一版没有转发,因此这样稍该一下
            
            height = [CellForWorkGroupRepost hyb_heightForTableView:tableView config:^(UITableViewCell *sourceCell) {
                CellForWorkGroupRepost *cell = (CellForWorkGroupRepost *)sourceCell;
                cell.model = model;   
            }];
            
        }
        else{
            height = [CellForWorkGroup hyb_heightForTableView:tableView config:^(UITableViewCell *sourceCell) {
                CellForWorkGroup *cell = (CellForWorkGroup *)sourceCell;
                cell.model = model;
            }];
        }
        
        //缓存高度
        if (model.dynamicId) {
            NSMutableDictionary *aDict = [NSMutableDictionary new];
            if (model.isOpening) {
                [aDict setObject:@(height) forKey:@"open"];
            }else{
                [aDict setObject:@(height) forKey:@"normal"];
            }
            [self.heightDict setObject:aDict forKey:model.dynamicId];
        }
        return height;
    }
    else{
        return 44.0f;
    }
}

效果图:

pic5 pic7 pic8 pic9

你的支持,我的动力!