处理好评论了

This commit is contained in:
2026-01-16 19:09:54 +08:00
parent 619c02f236
commit 3dfb8f31e2
9 changed files with 211 additions and 402 deletions

View File

@@ -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