短视频APP源码中关于短视频系统评论功能的实现方式

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yun_bao_2144899870/article/details/88235659

短视频系统中评论功能的分量在短视频功能里可谓是举足轻重,下面简单介绍下,云豹短视频系统中的评论功能的实现方式:
评论分为对视频的评论和对评论的回复两部分:
对于评论列表大家再熟悉不过了,就是一个tableview罢了,相信刚入门的技术也可以实现。技术的关键在于对评论的回复,我们使用了tableview的嵌套,即:在评论的cell中创建回复的tablview,使用代理功能来实现对数据和UI界面的精准控制,下面是实现的具体方式:

_contentL.attributedText = attstr;
    if ([_model.replys intValue] > 0) {
        CGFloat HHHH = 0.0;
        for (NSDictionary *dic in _replyArray) {
            detailmodel *model = [[detailmodel alloc]initWithDic:dic];
            HHHH += model.rowH;
        }
        if ([_model.replys intValue] == 1) {
            _tableHeight.constant = HHHH;
            _replyTable.tableFooterView = nil;
        }else{
//            if (!_replyBottomView) {
                NSLog(@"===%d",page);
                _model.replayView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 20)];
                _model.replayView.backgroundColor = CellRow_Cor;
                //回复
                UIButton * replyBtn = [UIButton buttonWithType:0];
                replyBtn.backgroundColor = [UIColor clearColor];
                replyBtn.titleLabel.textAlignment = NSTextAlignmentLeft;
                replyBtn.titleLabel.font = [UIFont systemFontOfSize:12];
                [replyBtn addTarget:self action:@selector(makeReply:) forControlEvents:UIControlEventTouchUpInside];
                BOOL showNum = NO;
                if (_model.replyList.count==1) {
                    showNum = YES;
                }
                [self changeMoreShowText:showNum andBtn:replyBtn];
                NSMutableAttributedString *attstr2 = [[NSMutableAttributedString alloc]initWithString:@"收起"];
                [attstr2 addAttribute:NSForegroundColorAttributeName value:RGB_COLOR(@"#969696", 1) range:NSMakeRange(0, 2)];
                NSTextAttachment *attach2 = [[NSTextAttachment alloc] init];
                UIImage *image2 = [UIImage imageNamed:@"relpay_三角上.png"];
                NSAttributedString *imageString2;
                if (image2) {
                    attach2.image = image2;
                    attach2.bounds = CGRectMake(0, -4, 15, 15);
                    imageString2 =   [NSAttributedString attributedStringWithAttachment:attach2];
                    [attstr2 appendAttributedString:imageString2];
                }
                [replyBtn setAttributedTitle:attstr2 forState:UIControlStateSelected];
                [_model.replayView addSubview:replyBtn];
                //记录按钮属性
                _model.replyMoreBtn = replyBtn;
                [replyBtn mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.top.bottom.equalTo(_model.replayView);
                    make.left.equalTo(_model.replayView).offset(26);
                }];       
                if ((_model.replyList.count % 10 != 0
                     && _model.replyList.count % 10 != 1
                     && _model.replyList.count% 10 != 3)
                     || ((_model.replyList.count+1)== [_model.replys intValue])
                    ) {
                    replyBtn.selected = YES;
                }else{
                    replyBtn.selected = NO;
                }
            _replyTable.tableFooterView = _model.replayView;
            _tableHeight.constant = HHHH+20;
        }
    }else{
        _tableHeight.constant = 0;
        _replyTable.tableFooterView = nil;
    }
- (void)makeReply:(UIButton *)replyBtn{
    if (replyBtn.selected) {
        NSDictionary *dic = [_replyArray firstObject];
        [_replyArray removeAllObjects];
        [_replyArray addObject:[dic mutableCopy]];
        _model.replyList = [_replyArray mutableCopy];
//        [_replyTable reloadData];
        replyBtn.selected = NO;
        [self changeMoreShowText:YES andBtn:replyBtn];
        [self.delegate reloadCurCell:_model andIndex:_curIndex andReplist:_replyArray needRefresh:YES];
    }else{     
        if (_replyArray.count == 1) {
            page = 1;
        }else{
            page ++;
        }
        [self requestData:NO andBtn:replyBtn];
    }
}
-(void)changeMoreShowText:(BOOL)isFirstPage andBtn:(UIButton *)replyBtn{
    NSString *tempStr;
    if (isFirstPage) {
        tempStr  = [NSString stringWithFormat:@"展开%d条回复",[_model.replys intValue]>=2?([_model.replys intValue]-1):(1)];
    }else{
        tempStr  = [NSString stringWithFormat:@"展开更多回复"];
    }
    NSMutableAttributedString *attstr = [[NSMutableAttributedString alloc]initWithString:tempStr];
    [attstr addAttribute:NSForegroundColorAttributeName value:RGB_COLOR(@"#969696", 1) range:NSMakeRange(0, tempStr.length)];
    NSTextAttachment *attach = [[NSTextAttachment alloc] init];
    UIImage *image = [UIImage imageNamed:@"relpay_三角下.png"];
    NSAttributedString *imageString;
    if (image) {
        attach.image = image;
        attach.bounds = CGRectMake(0, -4, 15, 15);
        imageString =   [NSAttributedString attributedStringWithAttachment:attach];
        [attstr appendAttributedString:imageString];
    }
    [replyBtn setAttributedTitle:attstr forState:0];
}

看了上述短视频APP源码评论功能的方法介绍,大家是不是眼前一亮?是不是豁然开朗?关于更多短视频系统功能的介绍可以关注我们的账号,我们会持续更新关于短视频功能介绍,如果想尽快了解我们的产品信息,可以直接联系我们,我们会为您解答疑惑。

猜你喜欢

转载自blog.csdn.net/yun_bao_2144899870/article/details/88235659