短视频系统中评论功能的分量在短视频功能里可谓是举足轻重,下面简单介绍下,短视频系统中的评论功能的实现方式:
评论分为对视频的评论和对评论的回复两部分:
对于评论列表大家再熟悉不过了,就是一个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]initWith :CGRectMake(0, 0, 100, 20)]; _model.replayView.backgroundColor = CellRow_Cor; //回复 UIButton * replyBtn = [UIButton buttonWithType:0]; replyBtn.backgroundColor = [UIColor clearColor]; replyBtn. Label.textAlignment = NSTextAlignmentLeft; replyBtn. Label.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 setAttributed :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 first ]; [_replyArray removeAll s]; [_replyArray add :[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 setAttributed :attstr forState:0];}看了上述短视频APP源码评论功能的方法介绍,大家是不是眼前一亮?是不是豁然开朗?关于更多短视频系统功能的介绍可以关注我们的账号,我们会持续更新关于短视频功能介绍。
继续阅读与本文标签相同的文章
上一篇 :
rancher使用阿里云容器服务NAS存储
-
[转]德里首都圈成印度最大创业中心,迄今诞生10家独角兽|全球快讯
2026-05-17栏目: 教程
-
[转]截至Q3美国风投总额达967亿美元,全年有望赶上2018年纪录|全球快讯
2026-05-17栏目: 教程
-
基因测序企业如何解决存储和计算需求与有限IT基础设施的矛盾
2026-05-17栏目: 教程
-
Spring Cloud Alibaba 从孵化到 "挂牌" 之旅
2026-05-17栏目: 教程
-
[转]国务院部署史上最大金融开放,“国际金融大鳄”将全面进入中国!
2026-05-17栏目: 教程
