1
This commit is contained in:
@@ -31,6 +31,11 @@ static const NSTimeInterval kTimestampInterval = 5 * 60; // 5 分钟
|
||||
@property (nonatomic, strong) AiVM *aiVM;
|
||||
@property (nonatomic, assign) BOOL hasMoreData;
|
||||
@property (nonatomic, assign) CGFloat contentBottomInset;
|
||||
@property (nonatomic, copy) NSString *introFooterText;
|
||||
@property (nonatomic, strong) UIView *introFooterContainer;
|
||||
@property (nonatomic, strong) UILabel *introFooterLabel;
|
||||
@property (nonatomic, assign) CGSize lastIntroFooterTableSize;
|
||||
@property (nonatomic, assign) BOOL applyingIntroFooter;
|
||||
|
||||
@end
|
||||
|
||||
@@ -135,6 +140,7 @@ static const NSTimeInterval kTimestampInterval = 5 * 60; // 5 分钟
|
||||
|
||||
self.tableView.transform = inverted ? CGAffineTransformMakeScale(1, -1) : CGAffineTransformIdentity;
|
||||
[self updateContentBottomInset:self.contentBottomInset];
|
||||
[self updateIntroFooterText:self.introFooterText];
|
||||
[self.tableView reloadData];
|
||||
[self.tableView layoutIfNeeded];
|
||||
}
|
||||
@@ -880,6 +886,85 @@ static inline CGFloat KBChatAbsTimeInterval(NSTimeInterval interval) {
|
||||
[self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
|
||||
}
|
||||
|
||||
- (void)updateIntroFooterText:(nullable NSString *)text {
|
||||
if (self.applyingIntroFooter) {
|
||||
return;
|
||||
}
|
||||
self.applyingIntroFooter = YES;
|
||||
self.introFooterText = text ?: @"";
|
||||
if (self.introFooterText.length == 0) {
|
||||
self.tableView.tableFooterView = nil;
|
||||
self.lastIntroFooterTableSize = CGSizeZero;
|
||||
self.applyingIntroFooter = NO;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!self.introFooterContainer) {
|
||||
self.introFooterContainer = [[UIView alloc] initWithFrame:CGRectZero];
|
||||
self.introFooterContainer.backgroundColor = [UIColor clearColor];
|
||||
|
||||
self.introFooterLabel = [[UILabel alloc] initWithFrame:CGRectZero];
|
||||
self.introFooterLabel.numberOfLines = 0;
|
||||
self.introFooterLabel.font = [UIFont systemFontOfSize:14];
|
||||
self.introFooterLabel.textColor = [[UIColor whiteColor] colorWithAlphaComponent:0.9];
|
||||
self.introFooterLabel.textAlignment = NSTextAlignmentCenter;
|
||||
[self.introFooterContainer addSubview:self.introFooterLabel];
|
||||
}
|
||||
|
||||
self.introFooterLabel.text = self.introFooterText;
|
||||
self.introFooterContainer.transform = self.inverted ? CGAffineTransformMakeScale(1, -1) : CGAffineTransformIdentity;
|
||||
|
||||
CGFloat width = CGRectGetWidth(self.tableView.bounds);
|
||||
if (width <= 0) {
|
||||
width = CGRectGetWidth(self.bounds);
|
||||
}
|
||||
CGFloat height = CGRectGetHeight(self.tableView.bounds);
|
||||
if (height <= 0) {
|
||||
height = CGRectGetHeight(self.bounds);
|
||||
}
|
||||
self.lastIntroFooterTableSize = CGSizeMake(width, height);
|
||||
|
||||
CGFloat horizontalPadding = 24;
|
||||
CGFloat verticalPadding = 16;
|
||||
CGFloat labelWidth = MAX(0, width - horizontalPadding * 2);
|
||||
CGSize labelSize = [self.introFooterLabel sizeThatFits:CGSizeMake(labelWidth, CGFLOAT_MAX)];
|
||||
CGFloat containerHeight = MAX(height, labelSize.height + verticalPadding * 2);
|
||||
|
||||
self.introFooterContainer.frame = CGRectMake(0, 0, width, containerHeight);
|
||||
self.introFooterLabel.frame = CGRectMake(horizontalPadding, verticalPadding, labelWidth, labelSize.height);
|
||||
self.tableView.tableFooterView = self.introFooterContainer;
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.tableView layoutIfNeeded];
|
||||
CGFloat contentHeight = self.tableView.contentSize.height;
|
||||
CGFloat tableHeight = CGRectGetHeight(self.tableView.bounds);
|
||||
CGFloat minOffset = -self.tableView.contentInset.top;
|
||||
CGFloat maxOffset = contentHeight - tableHeight + self.tableView.contentInset.bottom;
|
||||
if (maxOffset < minOffset) {
|
||||
maxOffset = minOffset;
|
||||
}
|
||||
CGFloat targetOffset = self.inverted ? maxOffset : minOffset;
|
||||
[self.tableView setContentOffset:CGPointMake(0, targetOffset) animated:NO];
|
||||
});
|
||||
self.applyingIntroFooter = NO;
|
||||
}
|
||||
|
||||
- (void)layoutSubviews {
|
||||
[super layoutSubviews];
|
||||
if (self.introFooterText.length == 0 || self.applyingIntroFooter) {
|
||||
return;
|
||||
}
|
||||
CGFloat width = CGRectGetWidth(self.tableView.bounds);
|
||||
CGFloat height = CGRectGetHeight(self.tableView.bounds);
|
||||
if (width <= 0 || height <= 0) {
|
||||
return;
|
||||
}
|
||||
CGSize size = CGSizeMake(width, height);
|
||||
if (!CGSizeEqualToSize(size, self.lastIntroFooterTableSize)) {
|
||||
[self updateIntroFooterText:self.introFooterText];
|
||||
}
|
||||
}
|
||||
|
||||
/// 判断是否需要插入时间戳
|
||||
- (BOOL)shouldInsertTimestampForMessage:(KBAiChatMessage *)message {
|
||||
// 第一条消息总是显示时间
|
||||
|
||||
Reference in New Issue
Block a user