From d479d1903b4bf80f10320bc8f5825b5e1fdaff6e Mon Sep 17 00:00:00 2001 From: CodeST <694468528@qq.com> Date: Thu, 15 Jan 2026 18:49:31 +0800 Subject: [PATCH] 2 --- .../close_icon.imageset/Contents.json | 22 +++++ .../close_icon.imageset/close_icon@2x.png | Bin 0 -> 1459 bytes .../close_icon.imageset/close_icon@3x.png | Bin 0 -> 2753 bytes CustomKeyboard/KeyboardViewController.m | 21 +++++ CustomKeyboard/View/KBChatMessageCell.m | 1 + CustomKeyboard/View/KBChatPanelView.h | 2 + CustomKeyboard/View/KBChatPanelView.m | 88 +++++++++++++++++- 7 files changed, 132 insertions(+), 2 deletions(-) create mode 100644 CustomKeyboard/KeyboardAssets.xcassets/close_icon.imageset/Contents.json create mode 100644 CustomKeyboard/KeyboardAssets.xcassets/close_icon.imageset/close_icon@2x.png create mode 100644 CustomKeyboard/KeyboardAssets.xcassets/close_icon.imageset/close_icon@3x.png diff --git a/CustomKeyboard/KeyboardAssets.xcassets/close_icon.imageset/Contents.json b/CustomKeyboard/KeyboardAssets.xcassets/close_icon.imageset/Contents.json new file mode 100644 index 0000000..8f9ae45 --- /dev/null +++ b/CustomKeyboard/KeyboardAssets.xcassets/close_icon.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "close_icon@2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "close_icon@3x.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/CustomKeyboard/KeyboardAssets.xcassets/close_icon.imageset/close_icon@2x.png b/CustomKeyboard/KeyboardAssets.xcassets/close_icon.imageset/close_icon@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..77df80096ada3290c6467f083155eec655e516a5 GIT binary patch literal 1459 zcmV;k1x)&hP)GR$_(7Nu{t@PV(8tFZbC|n6K?=T|49uXcC zr~~NZV~jb>y-ut^jt!bymQf^D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#OxdBfW(P)o?|yk%Toe3 zOch~EN$4XsV%+G)?CaEk#4%cm*zBxR{Wk&zR17L1CSt2|V;wNKK*XU%3jd|DR$#W} zl2&z42(b`Tts7&YpaK(zHdir|#SeANO;p8sEyO@9Oa@#SfrH74IJAm9(zaf8zN?ZY zi|5RvKBX%7jPJxy@5YpsuUQj^b{Xmx_=3;bI_7&RxkspaUI@P8^K4=enEbMKJSXB3 ztn5{NzOYW 0) { + NSString *tmpRoot = NSTemporaryDirectory(); + if (tmpRoot.length > 0 && + [msg.audioFilePath hasPrefix:tmpRoot]) { + [[NSFileManager defaultManager] removeItemAtPath:msg.audioFilePath + error:nil]; + } + } + } + [self.chatMessages removeAllObjects]; + [self.chatPanelView kb_reloadWithMessages:@[]]; + if (self.chatAudioPlayer.isPlaying) { + [self.chatAudioPlayer stop]; + } + self.chatAudioPlayer = nil; + [self showChatPanel:NO]; +} + #pragma mark - Chat Helpers - (void)kb_handleChatSendAction { @@ -1432,6 +1452,7 @@ static void KBSkinInstallNotificationCallback(CFNotificationCenterRef center, NSLog(@"⌨️[Keyboard] apply theme id=%@ hasBg=%d", t.skinId, (img != nil)); [self kb_logSkinDiagnosticsWithTheme:t backgroundImage:img]; self.bgImageView.image = img; +// [self.chatPanelView kb_setBackgroundImage:img]; BOOL hasImg = (img != nil); // 触发键区按主题重绘 if ([self.keyBoardMainView respondsToSelector:@selector(kb_applyTheme)]) { diff --git a/CustomKeyboard/View/KBChatMessageCell.m b/CustomKeyboard/View/KBChatMessageCell.m index fc4ef37..5b8dde7 100644 --- a/CustomKeyboard/View/KBChatMessageCell.m +++ b/CustomKeyboard/View/KBChatMessageCell.m @@ -21,6 +21,7 @@ - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { self.backgroundColor = [UIColor clearColor]; + self.contentView.backgroundColor = [UIColor clearColor]; self.selectionStyle = UITableViewCellSelectionStyleNone; [self.contentView addSubview:self.avatarView]; diff --git a/CustomKeyboard/View/KBChatPanelView.h b/CustomKeyboard/View/KBChatPanelView.h index 255ffec..8c4c2ac 100644 --- a/CustomKeyboard/View/KBChatPanelView.h +++ b/CustomKeyboard/View/KBChatPanelView.h @@ -12,6 +12,7 @@ NS_ASSUME_NONNULL_BEGIN @optional - (void)chatPanelView:(KBChatPanelView *)view didSendText:(NSString *)text; - (void)chatPanelView:(KBChatPanelView *)view didTapMessage:(KBChatMessage *)message; +- (void)chatPanelViewDidTapClose:(KBChatPanelView *)view; @end @interface KBChatPanelView : UIView @@ -20,6 +21,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, strong, readonly) UITableView *tableView; +//- (void)kb_setBackgroundImage:(nullable UIImage *)image; - (void)kb_reloadWithMessages:(NSArray *)messages; @end diff --git a/CustomKeyboard/View/KBChatPanelView.m b/CustomKeyboard/View/KBChatPanelView.m index bfb25b2..c2eb651 100644 --- a/CustomKeyboard/View/KBChatPanelView.m +++ b/CustomKeyboard/View/KBChatPanelView.m @@ -9,6 +9,10 @@ #import "Masonry.h" @interface KBChatPanelView () +//@property (nonatomic, strong) UIImageView *backgroundImageView; +@property (nonatomic, strong) UIView *headerView; +@property (nonatomic, strong) UILabel *titleLabel; +@property (nonatomic, strong) UIButton *closeButton; @property (nonatomic, strong) UITableView *tableViewInternal; @property (nonatomic, copy) NSArray *messages; @end @@ -17,13 +21,25 @@ - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { - self.backgroundColor = [UIColor colorWithHex:0xD1D3DB]; + self.backgroundColor = [UIColor clearColor]; +// [self addSubview:self.backgroundImageView]; + [self addSubview:self.headerView]; [self addSubview:self.tableViewInternal]; +// [self.backgroundImageView mas_makeConstraints:^(MASConstraintMaker *make) { +// make.edges.equalTo(self); +// }]; + + [self.headerView mas_makeConstraints:^(MASConstraintMaker *make) { + make.left.right.equalTo(self); + make.top.equalTo(self.mas_top); + make.height.mas_equalTo(KBFit(36.0f)); + }]; + [self.tableViewInternal mas_makeConstraints:^(MASConstraintMaker *make) { make.left.right.equalTo(self); - make.top.equalTo(self.mas_top).offset(8); + make.top.equalTo(self.headerView.mas_bottom).offset(4); make.bottom.equalTo(self.mas_bottom).offset(-8); }]; } @@ -43,6 +59,18 @@ } } +//- (void)kb_setBackgroundImage:(UIImage *)image { +// self.backgroundImageView.image = image; +//} + +#pragma mark - Actions + +- (void)kb_onTapClose { + if ([self.delegate respondsToSelector:@selector(chatPanelViewDidTapClose:)]) { + [self.delegate chatPanelViewDidTapClose:self]; + } +} + #pragma mark - UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { @@ -80,6 +108,7 @@ if (!_tableViewInternal) { _tableViewInternal = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; _tableViewInternal.backgroundColor = [UIColor clearColor]; + _tableViewInternal.backgroundView = nil; _tableViewInternal.separatorStyle = UITableViewCellSeparatorStyleNone; _tableViewInternal.dataSource = self; _tableViewInternal.delegate = self; @@ -90,6 +119,61 @@ return _tableViewInternal; } +- (UIView *)headerView { + if (!_headerView) { + _headerView = [[UIView alloc] init]; + _headerView.backgroundColor = [UIColor clearColor]; + [_headerView addSubview:self.titleLabel]; + [_headerView addSubview:self.closeButton]; + + [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { + make.left.equalTo(_headerView.mas_left).offset(12); + make.centerY.equalTo(_headerView); + }]; + + [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) { + make.right.equalTo(_headerView.mas_right).offset(-12); + make.centerY.equalTo(_headerView); + make.width.height.mas_equalTo(KBFit(24.0f)); + }]; + } + return _headerView; +} + +- (UILabel *)titleLabel { + if (!_titleLabel) { + _titleLabel = [[UILabel alloc] init]; + _titleLabel.font = [UIFont systemFontOfSize:13 weight:UIFontWeightMedium]; + _titleLabel.textColor = [UIColor colorWithHex:0x1B1F1A]; + _titleLabel.text = KBLocalized(@"AI对话"); + } + return _titleLabel; +} + +- (UIButton *)closeButton { + if (!_closeButton) { + _closeButton = [UIButton buttonWithType:UIButtonTypeCustom]; + UIImage *icon = [UIImage imageNamed:@"close_icon"]; + [_closeButton setImage:icon forState:UIControlStateNormal]; + _closeButton.backgroundColor = [UIColor clearColor]; + [_closeButton addTarget:self + action:@selector(kb_onTapClose) + forControlEvents:UIControlEventTouchUpInside]; + } + return _closeButton; +} + +//- (UIImageView *)backgroundImageView { +// if (!_backgroundImageView) { +// _backgroundImageView = [[UIImageView alloc] init]; +// _backgroundImageView.contentMode = UIViewContentModeScaleAspectFill; +// _backgroundImageView.clipsToBounds = YES; +// _backgroundImageView.backgroundColor = [UIColor clearColor]; +// _backgroundImageView.userInteractionEnabled = NO; +// } +// return _backgroundImageView; +//} + #pragma mark - Expose - (UITableView *)tableView { return self.tableViewInternal; }