短視訊系統中評論功能的分量在短視訊功能裡可謂是舉足輕重,下面簡單介紹下,短視訊系統中的評論功能的實作方式:
評論分為對視訊的評論和對評論的回複兩部分:
對于評論清單大家再熟悉不過了,就是一個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源碼評論功能的方法介紹,大家是不是眼前一亮?是不是豁然開朗?關于更多短視訊系統功能的介紹可以關注我們的賬号,我們會持續更新關于短視訊功能介紹。