This commit is contained in:
2026-02-02 20:36:38 +08:00
parent f1b52151be
commit 6e50cdcd2a
3 changed files with 143 additions and 29 deletions

View File

@@ -37,6 +37,11 @@ static const NSTimeInterval kTimestampInterval = 5 * 60; // 5 分钟
@property (nonatomic, assign) CGSize lastIntroFooterTableSize;
@property (nonatomic, assign) BOOL applyingIntroFooter;
@property (nonatomic, copy) NSString *remoteAudioToken;
@property (nonatomic, strong) UIView *topStatusView;
@property (nonatomic, strong) UIActivityIndicatorView *topLoadingIndicator;
@property (nonatomic, strong) UILabel *topStatusLabel;
@property (nonatomic, assign) BOOL isTopLoading;
@property (nonatomic, assign) BOOL isTopNoMore;
@end
@@ -427,6 +432,89 @@ static inline CGFloat KBChatAbsTimeInterval(NSTimeInterval interval) {
}
}
#pragma mark - Top Status
- (void)showTopLoading {
self.isTopLoading = YES;
self.isTopNoMore = NO;
[self updateTopStatusView];
}
- (void)hideTopLoading {
self.isTopLoading = NO;
[self updateTopStatusView];
}
- (void)showNoMoreData {
self.isTopNoMore = YES;
self.isTopLoading = NO;
[self updateTopStatusView];
}
- (void)hideNoMoreData {
self.isTopNoMore = NO;
[self updateTopStatusView];
}
- (void)updateTopStatusView {
BOOL shouldShow = self.isTopLoading || self.isTopNoMore;
if (!shouldShow) {
self.topStatusView.hidden = YES;
return;
}
if (!self.topStatusView) {
self.topStatusView = [[UIView alloc] initWithFrame:CGRectZero];
self.topStatusView.backgroundColor = [UIColor clearColor];
self.topStatusView.userInteractionEnabled = NO;
self.topLoadingIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleMedium];
self.topLoadingIndicator.hidesWhenStopped = YES;
[self.topStatusView addSubview:self.topLoadingIndicator];
self.topStatusLabel = [[UILabel alloc] initWithFrame:CGRectZero];
self.topStatusLabel.font = [UIFont systemFontOfSize:12];
self.topStatusLabel.textColor = [[UIColor whiteColor] colorWithAlphaComponent:0.8];
[self.topStatusView addSubview:self.topStatusLabel];
[self addSubview:self.topStatusView];
}
if (self.isTopLoading) {
self.topStatusLabel.text = KBLocalized(@"Loading...");
[self.topLoadingIndicator startAnimating];
} else if (self.isTopNoMore) {
self.topStatusLabel.text = KBLocalized(@"No more data");
[self.topLoadingIndicator stopAnimating];
}
CGFloat width = CGRectGetWidth(self.tableView.bounds);
if (width <= 0) {
width = CGRectGetWidth(self.bounds);
}
CGFloat height = 32;
self.topStatusView.frame = CGRectMake(0, 0, width, height);
self.topStatusView.hidden = NO;
[self bringSubviewToFront:self.topStatusView];
CGSize labelSize = [self.topStatusLabel sizeThatFits:CGSizeMake(width - 40, height)];
CGFloat totalWidth = labelSize.width + (self.isTopLoading ? 20 + 6 : 0);
CGFloat startX = (width - totalWidth) / 2.0;
if (self.isTopLoading) {
self.topLoadingIndicator.frame = CGRectMake(startX, (height - 20) / 2.0, 20, 20);
self.topStatusLabel.frame = CGRectMake(CGRectGetMaxX(self.topLoadingIndicator.frame) + 6,
(height - labelSize.height) / 2.0,
labelSize.width,
labelSize.height);
} else {
self.topStatusLabel.frame = CGRectMake((width - labelSize.width) / 2.0,
(height - labelSize.height) / 2.0,
labelSize.width,
labelSize.height);
}
}
- (void)scrollToBottom {
[self scrollToBottomAnimated:YES];
}