修改动画

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

@@ -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
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);
}
NSLog(@"[KBAIHomeVC] 更新 ChatView 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];