修改bug

This commit is contained in:
2026-01-27 17:03:16 +08:00
parent 2b749cd2b0
commit e67bc37571
4 changed files with 134 additions and 35 deletions

View File

@@ -64,9 +64,16 @@ static const NSTimeInterval kTimestampInterval = 5 * 60; // 5 分钟
self.tableView.delegate = self;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.estimatedRowHeight = 60;
// 使0
self.tableView.estimatedRowHeight = 80;
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.estimatedSectionFooterHeight = 0;
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.showsVerticalScrollIndicator = YES;
// CollectionView
if (@available(iOS 11.0, *)) {
self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
[self addSubview:self.tableView];
// Cell
@@ -182,13 +189,22 @@ static const NSTimeInterval kTimestampInterval = 5 * 60; // 5 分钟
}
- (void)scrollToBottom {
[self scrollToBottomAnimated:YES];
}
- (void)scrollToBottomAnimated:(BOOL)animated {
if (self.messages.count == 0) return;
// 使 layoutIfNeeded
[self.tableView layoutIfNeeded];
NSIndexPath *lastIndexPath = [NSIndexPath indexPathForRow:self.messages.count - 1
inSection:0];
//
[self.tableView scrollToRowAtIndexPath:lastIndexPath
atScrollPosition:UITableViewScrollPositionBottom
animated:YES];
animated:animated];
}
#pragma mark - Public Helpers
@@ -240,6 +256,10 @@ static const NSTimeInterval kTimestampInterval = 5 * 60; // 5 分钟
for (NSInteger i = oldCount; i < newCount; i++) {
[indexPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]];
}
//
[self.tableView layoutIfNeeded];
[self.tableView insertRowsAtIndexPaths:indexPaths
withRowAnimation:UITableViewRowAnimationNone];
}
@@ -247,8 +267,10 @@ static const NSTimeInterval kTimestampInterval = 5 * 60; // 5 分钟
[self updateFooterVisibility];
if (autoScroll) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self scrollToBottom];
// 使 dispatch_async
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView layoutIfNeeded]; //
[self scrollToBottomAnimated:YES];
});
}
}
@@ -274,14 +296,14 @@ static const NSTimeInterval kTimestampInterval = 5 * 60; // 5 分钟
CGFloat newContentHeight = self.tableView.contentSize.height;
CGFloat delta = newContentHeight - oldContentHeight;
CGFloat offsetY = oldOffsetY + delta;
// 使 offset
[self.tableView setContentOffset:CGPointMake(0, offsetY) animated:NO];
return;
}
if (scrollToBottom) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self scrollToBottom];
});
// 使
[self scrollToBottomAnimated:NO];
}
}
@@ -430,6 +452,31 @@ static const NSTimeInterval kTimestampInterval = 5 * 60; // 5 分钟
}
}
///
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView
withVelocity:(CGPoint)velocity
targetContentOffset:(inout CGPoint *)targetContentOffset {
CGFloat offsetY = scrollView.contentOffset.y;
CGFloat contentHeight = scrollView.contentSize.height;
CGFloat scrollViewHeight = scrollView.bounds.size.height;
//
if (contentHeight <= scrollViewHeight) {
scrollView.bounces = NO;
} else {
scrollView.bounces = YES;
//
if (velocity.y < 0) { //
CGFloat maxOffset = contentHeight - scrollViewHeight + scrollView.contentInset.bottom;
if (targetContentOffset->y > maxOffset) {
targetContentOffset->y = maxOffset;
}
}
}
}
#pragma mark - KBChatAssistantMessageCellDelegate
- (void)assistantMessageCell:(KBChatAssistantMessageCell *)cell