处理好评论了
This commit is contained in:
@@ -64,37 +64,55 @@
|
||||
return KBAIReplyFooterStateHidden;
|
||||
}
|
||||
|
||||
// 未展开(初始状态)
|
||||
if (!self.isRepliesExpanded) {
|
||||
return KBAIReplyFooterStateExpand;
|
||||
// 已展开
|
||||
if (self.isRepliesExpanded) {
|
||||
return KBAIReplyFooterStateCollapse;
|
||||
}
|
||||
|
||||
// 已展开但还有更多
|
||||
if (self.displayedReplies.count < self.totalReplyCount) {
|
||||
return KBAIReplyFooterStateLoadMore;
|
||||
}
|
||||
|
||||
// 全部展开,显示收起
|
||||
return KBAIReplyFooterStateCollapse;
|
||||
// 未展开
|
||||
return KBAIReplyFooterStateExpand;
|
||||
}
|
||||
|
||||
- (void)loadMoreReplies:(NSInteger)count {
|
||||
- (void)expandAllReplies {
|
||||
self.isRepliesExpanded = YES;
|
||||
|
||||
NSInteger currentCount = self.displayedReplies.count;
|
||||
NSInteger endIndex = MIN(currentCount + count, self.replies.count);
|
||||
|
||||
for (NSInteger i = currentCount; i < endIndex; i++) {
|
||||
[self.displayedReplies addObject:self.replies[i]];
|
||||
}
|
||||
|
||||
self.hasMoreReplies = (self.displayedReplies.count < self.totalReplyCount);
|
||||
[self.displayedReplies removeAllObjects];
|
||||
[self.displayedReplies addObjectsFromArray:self.replies];
|
||||
}
|
||||
|
||||
- (void)collapseReplies {
|
||||
self.isRepliesExpanded = NO;
|
||||
[self.displayedReplies removeAllObjects];
|
||||
self.hasMoreReplies = self.totalReplyCount > 0;
|
||||
}
|
||||
|
||||
- (CGFloat)calculateHeaderHeightWithMaxWidth:(CGFloat)maxWidth {
|
||||
if (self.cachedHeaderHeight > 0) {
|
||||
return self.cachedHeaderHeight;
|
||||
}
|
||||
|
||||
// Header 布局:
|
||||
// 头像(40) + 间距(12) + 内容区域 + 间距(50,点赞按钮) + 右边距(16)
|
||||
// 内容区域宽度 = maxWidth - 16(左边距) - 40(头像) - 12(间距) - 50(点赞) - 16(右边距)
|
||||
CGFloat contentWidth = maxWidth - 16 - 40 - 12 - 50 - 16;
|
||||
|
||||
// 用户名高度(单行)
|
||||
CGFloat userNameHeight = 17; // 14号字体
|
||||
|
||||
// 时间高度(单行)
|
||||
CGFloat timeHeight = 15; // 12号字体
|
||||
|
||||
// 内容高度(多行)
|
||||
UIFont *contentFont = [UIFont systemFontOfSize:15];
|
||||
CGRect contentRect = [self.content boundingRectWithSize:CGSizeMake(contentWidth, CGFLOAT_MAX)
|
||||
options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading
|
||||
attributes:@{NSFontAttributeName: contentFont}
|
||||
context:nil];
|
||||
CGFloat contentHeight = ceil(contentRect.size.height);
|
||||
|
||||
// 总高度 = 上边距(12) + 用户名 + 间距(2) + 时间 + 间距(8) + 内容 + 下边距(12)
|
||||
CGFloat totalHeight = 12 + userNameHeight + 2 + timeHeight + 8 + contentHeight + 12;
|
||||
|
||||
self.cachedHeaderHeight = totalHeight;
|
||||
return totalHeight;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user