修改动画

This commit is contained in:
2026-01-28 17:21:19 +08:00
parent b4db79eba8
commit 1b9ce1622d
5 changed files with 71 additions and 16 deletions

View File

@@ -24,7 +24,7 @@ static const NSTimeInterval kTimestampInterval = 5 * 60; // 5 分钟
@interface KBChatTableView () <UITableViewDataSource, UITableViewDelegate, KBChatAssistantMessageCellDelegate, AVAudioPlayerDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) BaseTableView *tableView;
@property (nonatomic, strong) NSMutableArray<KBAiChatMessage *> *messages;
@property (nonatomic, strong) AVAudioPlayer *audioPlayer;
@property (nonatomic, strong) NSIndexPath *playingCellIndexPath;
@@ -58,8 +58,9 @@ static const NSTimeInterval kTimestampInterval = 5 * 60; // 5 分钟
self.hasMoreData = YES;
// TableView
self.tableView = [[UITableView alloc] initWithFrame:self.bounds
self.tableView = [[BaseTableView alloc] initWithFrame:self.bounds
style:UITableViewStylePlain];
self.tableView.useEmptyDataSet = false;
self.tableView.dataSource = self;
self.tableView.delegate = self;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

View File

@@ -7,12 +7,14 @@
#import <UIKit/UIKit.h>
#import "KBPersonaModel.h"
#import "KBChatTableView.h"
NS_ASSUME_NONNULL_BEGIN
/// 人设聊天 Cell
@interface KBPersonaChatCell : UICollectionViewCell
/// 聊天列表
@property (nonatomic, strong) KBChatTableView *chatView;
/// 人设数据
@property (nonatomic, strong) KBPersonaModel *persona;

View File

@@ -6,7 +6,6 @@
//
#import "KBPersonaChatCell.h"
#import "KBChatTableView.h"
#import "KBAiChatMessage.h"
#import "KBChatHistoryPageModel.h"
#import "AiVM.h"
@@ -30,8 +29,7 @@
///
@property (nonatomic, strong) UILabel *openingLabel;
///
@property (nonatomic, strong) KBChatTableView *chatView;
///
@property (nonatomic, strong) NSMutableArray<KBAiChatMessage *> *messages;

View File

@@ -86,11 +86,11 @@
//
[self addSubview:self.inputContainer];
[self.inputContainer mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.statusLabel.mas_bottom).offset(12);
// make.top.equalTo(self.statusLabel.mas_bottom).offset(12);
make.left.equalTo(self).offset(20);
make.right.equalTo(self).offset(-20);
make.height.mas_equalTo(50);
make.bottom.lessThanOrEqualTo(self).offset(-16);
make.bottom.lessThanOrEqualTo(self).offset(-10);
}];
UILongPressGestureRecognizer *longPress =

View File

@@ -110,8 +110,8 @@
#pragma mark - 1
- (void)setupUI {
self.voiceInputBarHeight = 150.0;
self.baseInputBarBottomSpacing = 20.0;
self.voiceInputBarHeight = 120.0;
self.baseInputBarBottomSpacing = KB_TABBAR_HEIGHT;
[self.view addSubview:self.collectionView];
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
@@ -350,12 +350,30 @@
NSTimeInterval duration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
UIViewAnimationOptions options = ([userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue] << 16);
// frame view
CGRect convertedFrame = [self.view convertRect:endFrame fromView:nil];
CGFloat keyboardHeight = MAX(0.0, CGRectGetMaxY(self.view.bounds) - CGRectGetMinY(convertedFrame));
self.currentKeyboardHeight = keyboardHeight;
CGFloat bottomSpacing = (keyboardHeight > 0.0) ? (keyboardHeight + 8.0) : self.baseInputBarBottomSpacing;
NSLog(@"[KBAIHomeVC] 键盘高度: %.2f, 屏幕高度: %.2f, 键盘 Y: %.2f",
keyboardHeight, CGRectGetMaxY(self.view.bounds), CGRectGetMinY(convertedFrame));
// 1 VoiceInputBar view.bottom
CGFloat bottomSpacing;
if (keyboardHeight > 0.0) {
// VoiceInputBar 5px
// bottomSpacing = - 5px offset
bottomSpacing = keyboardHeight - 5.0;
} else {
//
bottomSpacing = self.baseInputBarBottomSpacing;
}
NSLog(@"[KBAIHomeVC] VoiceInputBar bottomSpacing: %.2f", bottomSpacing);
[self.voiceInputBarBottomConstraint setOffset:-bottomSpacing];
// 2 ChatView bottomInset
[self updateChatViewBottomInset];
[UIView animateWithDuration:duration
@@ -433,13 +451,49 @@
#pragma mark - Private
- (void)updateChatViewBottomInset {
CGFloat bottomSpacing = (self.currentKeyboardHeight > 0.0) ? (self.currentKeyboardHeight + 8.0) : self.baseInputBarBottomSpacing;
// 2 bottomInset VoiceInputBar
CGFloat bottomInset;
// bottomInset chatView avatar
// 20 chatView
CGFloat bottomInset = 20; //
if (self.currentKeyboardHeight > 0.0) {
//
// avatarImageView = KB_TABBAR_HEIGHT + 50 + 20
// chatView = KB_TABBAR_HEIGHT + 50 + 20 + 54() + 10() 153
// VoiceInputBar chatView
// bottomInset = + VoiceInputBar - chatView
NSLog(@"[KBAIHomeVC] 更新 ChatView bottomInset: %.2f", bottomInset);
CGFloat avatarBottomSpace = KB_TABBAR_HEIGHT + 50 + 20; // avatarImageView
CGFloat chatViewPhysicalBottomSpace = avatarBottomSpace + 54 + 10; // chatView
// = ( + InputBar) - chatView
bottomInset = (self.currentKeyboardHeight + self.voiceInputBarHeight) - chatViewPhysicalBottomSpace;
//
bottomInset = MAX(bottomInset, 20);
NSLog(@"[KBAIHomeVC] 键盘弹起 - bottomInset: %.2f (键盘: %.2f + InputBar: %.2f - 已避开: %.2f)",
bottomInset, self.currentKeyboardHeight, self.voiceInputBarHeight, chatViewPhysicalBottomSpace);
} else {
// bottomInset
bottomInset = 20; //
NSLog(@"[KBAIHomeVC] 键盘隐藏 - bottomInset: %.2f", bottomInset);
}
for (NSIndexPath *indexPath in self.collectionView.indexPathsForVisibleItems) {
KBPersonaChatCell *cell = (KBPersonaChatCell *)[self.collectionView cellForItemAtIndexPath:indexPath];
if (cell) {
[cell updateChatViewBottomInset:bottomInset];
//
if (self.currentKeyboardHeight > 0.0) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[cell.chatView scrollToBottom]; // 使
});
}
}
}
NSLog(@"[KBAIHomeVC] 更新 ChatView bottomInset: %.2f (键盘高度: %.2f)", bottomInset, self.currentKeyboardHeight);
for (NSIndexPath *indexPath in self.collectionView.indexPathsForVisibleItems) {
KBPersonaChatCell *cell = (KBPersonaChatCell *)[self.collectionView cellForItemAtIndexPath:indexPath];