Browse Source

解决聊天键盘弹出位置不正确的问题

100Years 2 months ago
parent
commit
6e7c4a5088

+ 10 - 6
AIEmoji.xcodeproj/project.pbxproj

@@ -53,7 +53,7 @@
 		A89EA67A2D59D25F000EB181 /* TSAIChatVM.swift in Sources */ = {isa = PBXBuildFile; fileRef = A89EA6792D59D248000EB181 /* TSAIChatVM.swift */; };
 		A89EA67D2D59F1AF000EB181 /* StreamPostRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = A89EA67C2D59F1AC000EB181 /* StreamPostRequest.swift */; };
 		A89EA6812D59F44D000EB181 /* TSAIChatVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A89EA6802D59F440000EB181 /* TSAIChatVC.swift */; };
-		A89EA6832D59F4F9000EB181 /* TSChatViewController+Ex.swift in Sources */ = {isa = PBXBuildFile; fileRef = A89EA6822D59F4F1000EB181 /* TSChatViewController+Ex.swift */; };
+		A89EA6832D59F4F9000EB181 /* TSChatViewController+ChatDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A89EA6822D59F4F1000EB181 /* TSChatViewController+ChatDelegate.swift */; };
 		A89EA6A32D5B26E3000EB181 /* TSDBAIChatList.swift in Sources */ = {isa = PBXBuildFile; fileRef = A89EA6A22D5B26E3000EB181 /* TSDBAIChatList.swift */; };
 		A89EA6AC2D5B3EFB000EB181 /* TSRealmManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A89EA6AB2D5B3EFA000EB181 /* TSRealmManager.swift */; };
 		A89EA6B12D5C9D0C000EB181 /* TSAIChatHistoryVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A89EA6B02D5C9D0B000EB181 /* TSAIChatHistoryVC.swift */; };
@@ -65,6 +65,7 @@
 		A89EA6C12D5ED289000EB181 /* TSChatCellConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = A89EA6C02D5ED278000EB181 /* TSChatCellConfig.swift */; };
 		A89EA6C42D5F40CC000EB181 /* TSChatInputBarVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A89EA6C32D5F40CB000EB181 /* TSChatInputBarVC.swift */; };
 		A89EA6C62D5F5C22000EB181 /* TSChatInputFullScreenVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A89EA6C52D5F5C21000EB181 /* TSChatInputFullScreenVC.swift */; };
+		A89EA6C82D6359ED000EB181 /* TSChatViewController+View.swift in Sources */ = {isa = PBXBuildFile; fileRef = A89EA6C72D6359EA000EB181 /* TSChatViewController+View.swift */; };
 		A8EEADD42D3E6C660032C5A0 /* Flower💐.json in Resources */ = {isa = PBXBuildFile; fileRef = A8EEADD32D3E6C610032C5A0 /* Flower💐.json */; };
 		A8EEADD62D3E6CD80032C5A0 /* Fish🐠.json in Resources */ = {isa = PBXBuildFile; fileRef = A8EEADD52D3E6CD30032C5A0 /* Fish🐠.json */; };
 		A8EEADD82D3E74D20032C5A0 /* Pink🩷.json in Resources */ = {isa = PBXBuildFile; fileRef = A8EEADD72D3E74CB0032C5A0 /* Pink🩷.json */; };
@@ -170,7 +171,7 @@
 		A89EA6792D59D248000EB181 /* TSAIChatVM.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TSAIChatVM.swift; sourceTree = "<group>"; };
 		A89EA67C2D59F1AC000EB181 /* StreamPostRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StreamPostRequest.swift; sourceTree = "<group>"; };
 		A89EA6802D59F440000EB181 /* TSAIChatVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TSAIChatVC.swift; sourceTree = "<group>"; };
-		A89EA6822D59F4F1000EB181 /* TSChatViewController+Ex.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TSChatViewController+Ex.swift"; sourceTree = "<group>"; };
+		A89EA6822D59F4F1000EB181 /* TSChatViewController+ChatDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TSChatViewController+ChatDelegate.swift"; sourceTree = "<group>"; };
 		A89EA6A22D5B26E3000EB181 /* TSDBAIChatList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TSDBAIChatList.swift; sourceTree = "<group>"; };
 		A89EA6AB2D5B3EFA000EB181 /* TSRealmManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TSRealmManager.swift; sourceTree = "<group>"; };
 		A89EA6B02D5C9D0B000EB181 /* TSAIChatHistoryVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TSAIChatHistoryVC.swift; sourceTree = "<group>"; };
@@ -182,6 +183,7 @@
 		A89EA6C02D5ED278000EB181 /* TSChatCellConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TSChatCellConfig.swift; sourceTree = "<group>"; };
 		A89EA6C32D5F40CB000EB181 /* TSChatInputBarVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TSChatInputBarVC.swift; sourceTree = "<group>"; };
 		A89EA6C52D5F5C21000EB181 /* TSChatInputFullScreenVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TSChatInputFullScreenVC.swift; sourceTree = "<group>"; };
+		A89EA6C72D6359EA000EB181 /* TSChatViewController+View.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TSChatViewController+View.swift"; sourceTree = "<group>"; };
 		A8EEADD32D3E6C610032C5A0 /* Flower💐.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "Flower💐.json"; sourceTree = "<group>"; };
 		A8EEADD52D3E6CD30032C5A0 /* Fish🐠.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "Fish🐠.json"; sourceTree = "<group>"; };
 		A8EEADD72D3E74CB0032C5A0 /* Pink🩷.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; path = "Pink🩷.json"; sourceTree = "<group>"; };
@@ -467,7 +469,8 @@
 				A89EA6782D59D238000EB181 /* ViewModel */,
 				A89EA6682D59AA31000EB181 /* Views */,
 				A89EA65E2D59AA11000EB181 /* TSChatViewController.swift */,
-				A89EA6822D59F4F1000EB181 /* TSChatViewController+Ex.swift */,
+				A89EA6822D59F4F1000EB181 /* TSChatViewController+ChatDelegate.swift */,
+				A89EA6C72D6359EA000EB181 /* TSChatViewController+View.swift */,
 				A89EA6802D59F440000EB181 /* TSAIChatVC.swift */,
 				A89EA64D2D59A9F4000EB181 /* Layout */,
 				A89EA6532D59A9F4000EB181 /* Models */,
@@ -1072,6 +1075,7 @@
 				A80E72792D42285500C64288 /* TSBootPageVC.swift in Sources */,
 				A80E726A2D409E5400C64288 /* TSDiyTLYFlowersView.swift in Sources */,
 				A8F7764E2D3E00A800AA6E93 /* TSEmojisColViewModel.swift in Sources */,
+				A89EA6C82D6359ED000EB181 /* TSChatViewController+View.swift in Sources */,
 				A8F776422D3B75FC00AA6E93 /* TSBottomAlertVC.swift in Sources */,
 				A8F775192D38EC6800AA6E93 /* TSEmojisVC.swift in Sources */,
 				A80E725C2D3FB09400C64288 /* TSKeyboardView.swift in Sources */,
@@ -1139,7 +1143,7 @@
 				A8F7750A2D38EA8C00AA6E93 /* TSNetworkTool.swift in Sources */,
 				A8F7762D2D3A74A100AA6E93 /* TSGenmojiGennerateCell.swift in Sources */,
 				A89EA6BC2D5DFB12000EB181 /* TSViewController.swift in Sources */,
-				A89EA6832D59F4F9000EB181 /* TSChatViewController+Ex.swift in Sources */,
+				A89EA6832D59F4F9000EB181 /* TSChatViewController+ChatDelegate.swift in Sources */,
 				A89EA6A32D5B26E3000EB181 /* TSDBAIChatList.swift in Sources */,
 				A8F7753F2D39340E00AA6E93 /* TSSetingVC.swift in Sources */,
 				A8F7762B2D3A70B200AA6E93 /* PaddedLabel.swift in Sources */,
@@ -1193,7 +1197,7 @@
 					"$(inherited)",
 					"@executable_path/Frameworks",
 				);
-				MARKETING_VERSION = 1.1;
+				MARKETING_VERSION = 1.3;
 				PRODUCT_BUNDLE_IDENTIFIER = com.girl.music.wallpaper;
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
@@ -1232,7 +1236,7 @@
 					"$(inherited)",
 					"@executable_path/Frameworks",
 				);
-				MARKETING_VERSION = 1.1;
+				MARKETING_VERSION = 1.3;
 				PRODUCT_BUNDLE_IDENTIFIER = com.girl.music.wallpaper;
 				PRODUCT_NAME = "$(TARGET_NAME)";
 				SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";

+ 6 - 4
AIEmoji/Business/AIChat/TSAIChatContainerVC.swift

@@ -5,7 +5,7 @@
 //  Created by 100Years on 2025/2/9.
 //
 
-class TSAIChatContainerVC: TSBaseVC {
+class TSAIChatContainer111VC111: TSBaseVC {
     
     
     
@@ -83,7 +83,7 @@ class TSAIChatContainerVC: TSBaseVC {
     
     
     override func createView() {
-        edgesForExtendedLayout = []
+//        edgesForExtendedLayout = []
     
         if viewModel.uiStyle == .history {
             addNormalNavBarView()
@@ -95,12 +95,14 @@ class TSAIChatContainerVC: TSBaseVC {
                 make.edges.equalToSuperview()
             }
         }
-        
+//        setNavBarViewHidden(true)
         addChild(chatVC)
         contentView.addSubview(chatVC.view)
         
         chatVC.view.snp.makeConstraints { make in
-            make.edges.equalToSuperview()
+            make.bottom.leading.trailing.equalTo(0)
+            make.top.equalTo(-k_Nav_Height)
+//            make.top.equalTo(0)
         }
         
     }

+ 1 - 1
AIEmoji/Business/AIChat/TSAIChatHistoryVC/TSAIChatHistoryVC.swift

@@ -115,7 +115,7 @@ extension TSAIChatHistoryVC: UICollectionViewDataSource ,UICollectionViewDelegat
            let itemModel = sectionModel.chatList.safeObj(At: indexPath.item)
         {
             
-            let chatVC = TSAIChatContainerVC()
+            let chatVC = TSChatViewController()
             chatVC.viewModel.uiStyle = .history
             chatVC.viewModel.dbAIChatList = itemModel
             chatVC.deleteBlock = { [weak self]  in

+ 0 - 0
AIEmoji/Business/AIChat/TSChatViewController/TSChatViewController+Ex.swift → AIEmoji/Business/AIChat/TSChatViewController/TSChatViewController+ChatDelegate.swift


+ 159 - 0
AIEmoji/Business/AIChat/TSChatViewController/TSChatViewController+View.swift

@@ -0,0 +1,159 @@
+//
+//  TSChatViewController+View.swift
+//  AIEmoji
+//
+//  Created by 100Years on 2025/2/17.
+//
+
+extension TSChatViewController {
+    
+    
+     var creatVipBtn: UIButton{
+        let vipBtn = UIButton.createButton(image: UIImage(named: "nav_vip")) { [weak self]  in
+            guard let self = self else { return }
+            TSPurchaseVC.show(target: self) {
+      
+            }
+        }
+        return vipBtn
+    }
+    
+     var creatNavBarView: TSBaseNavContentBarView{
+        let navBarView = TSBaseNavContentBarView()
+        
+        let titleImageView = UIImageView.createImageView(imageName: "nav_title_aichat",contentMode: .scaleToFill)
+        navBarView.barView.addSubview(titleImageView)
+        titleImageView.snp.makeConstraints { make in
+            make.centerY.equalToSuperview()
+            make.left.equalTo(16)
+        }
+        
+        let setBtn = UIButton.createButton(image: UIImage(named: "setting")) { [weak self]  in
+            guard let self = self else { return }
+            let setingVC = TSSetingVC()
+            setingVC.hidesBottomBarWhenPushed = true
+            navigationController?.pushViewController(setingVC, animated: true)
+        }
+        navBarView.barView.addSubview(setBtn)
+        setBtn.snp.makeConstraints { make in
+            make.centerY.equalToSuperview()
+            make.trailing.equalTo(-16)
+            make.width.height.equalTo(24)
+        }
+        
+        let historyBtn = UIButton.createButton(image: UIImage(named: "aichat_history")) { [weak self]  in
+            guard let self = self else { return }
+            let historyVC = TSAIChatHistoryVC()
+            historyVC.hidesBottomBarWhenPushed = true
+            navigationController?.pushViewController(historyVC, animated: true)
+        }
+        navBarView.barView.addSubview(historyBtn)
+        historyBtn.snp.makeConstraints { make in
+            make.centerY.equalToSuperview()
+            make.trailing.equalTo(-60)
+            make.width.height.equalTo(24)
+        }
+        
+        navBarView.barView.addSubview(vipBtn)
+        vipBtn.snp.makeConstraints { make in
+            make.centerY.equalToSuperview()
+            make.trailing.equalTo(-104)
+            make.width.height.equalTo(24)
+        }
+        
+        return navBarView
+    }
+    
+    
+    var creatInputBarBgView:UIView{
+        let inputBarBgView = UIView()
+        inputBarBgView.addShadow(shadowColor: "#111111".uiColor.cgColor, shadowOffset: CGSize(width: 0, height: -10), shadowRadius: 10, shadowOpacity: 1.0)
+        return inputBarBgView
+    }
+    
+    
+    var creatFreeText: UILabel{
+        let textLabel = UILabel.createLabel(
+            text: "Remaining \(kPurchaseDefault.freeNum(type: .aichat)) free times",
+            font: .font(size: 12),
+            textColor: "#E83E3E".uiColor,
+            textAlignment: .center,
+            numberOfLines: 0
+        )
+        textLabel.isHidden = false
+        return textLabel
+    }
+    
+    
+    var creatUpgradeVipBg: UIView{
+        let upgradeVipBg = UIView()
+        
+        let imageView = UIImageView.createImageView(imageName: "vip_upgrade_bg",contentMode: .scaleToFill)
+        upgradeVipBg.addSubview(imageView)
+        imageView.snp.makeConstraints { make in
+            make.edges.equalToSuperview()
+        }
+        
+        let label = UILabel.createLabel(
+            text:"Free usage limit reached. Upgrade for unlimited chats.".localized,
+            font: .font(size: 14,weight: .bold),
+            textColor: "#111111".uiColor,
+            numberOfLines: 0
+        )
+        upgradeVipBg.addSubview(label)
+        label.snp.makeConstraints { make in
+            make.leading.equalTo(16)
+            make.top.equalTo(8)
+            make.bottom.equalTo(-8)
+            make.trailing.equalTo(-95)
+        }
+        
+        let upgradeBtn = UIButton.createButton(
+            title: "Upgrade".localized,
+            backgroundColor: "#111111".uiColor,
+            font:.font(size: 12,weight: .medium),
+            titleColor:.white,
+            corner: 14) { [weak self]  in
+                guard let self = self else { return }
+                TSPurchaseVC.show(target: self) { [weak self]  in
+//                    guard let self = self else { return }
+//                    updateVipView()
+                }
+            }
+        upgradeVipBg.addSubview(upgradeBtn)
+        upgradeBtn.snp.makeConstraints { make in
+            make.trailing.equalTo(-12)
+            make.centerY.equalToSuperview()
+            make.width.equalTo(70)
+            make.height.equalTo(28)
+        }
+        return upgradeVipBg
+    }
+    
+    
+    var creatScrollToBottomButton: UIButton{
+        let backBottomBtn = UIButton.createButton(image: UIImage(named: "down_arrow_line")) { [weak self]  in
+            guard let self = self else { return }
+            messagesCollectionView.scrollToLastItem(animated: false)
+        }
+        backBottomBtn.isHidden = true
+        backBottomBtn.backgroundColor = .popupColor
+        backBottomBtn.cornerRadius = 16.0
+        return backBottomBtn
+    }
+    
+    
+    
+   var creatNavBarContentView: UIView{
+        let view = UIView()
+        view.backgroundColor = .clear
+        return view
+    }
+    
+    var creatNormalNavBarView: TSNormalNavigationBarView{
+        let view = TSNormalNavigationBarView()
+        return view
+    }
+    
+    
+}

+ 169 - 84
AIEmoji/Business/AIChat/TSChatViewController/TSChatViewController.swift

@@ -24,15 +24,17 @@
 import InputBarAccessoryView
 import MessageKit
 import UIKit
-import MapKit
-// MARK: - TSChatViewController
 
-/// A base class for the example controllers
 class TSChatViewController: MessagesViewController, MessagesDataSource {
-    // MARK: Internal
+
     var viewModel:TSAIChatVM = TSAIChatVM()
     
     
+    public lazy var navBarContentView: UIView = creatNavBarContentView
+    
+    public lazy var normalNavBarView: TSNormalNavigationBarView = creatNormalNavBarView
+    
+    
     // MARK: - Public properties
     lazy var messageList: [TSChatMessage] = []
     
@@ -55,84 +57,18 @@ class TSChatViewController: MessagesViewController, MessagesDataSource {
     }()
     
     
-    let inputBarBgView:UIView = {
-        let inputBarBgView = UIView()
-        inputBarBgView.addShadow(shadowColor: "#111111".uiColor.cgColor, shadowOffset: CGSize(width: 0, height: -10), shadowRadius: 10, shadowOpacity: 1.0)
-        return inputBarBgView
-    }()
-    let inputBarTopView:UIView = UIView()
-    
-    //免费次数
-    lazy var freeText: UILabel = {
-        let textLabel = UILabel.createLabel(
-            text: "Remaining \(kPurchaseDefault.freeNum(type: .aichat)) free times",
-            font: .font(size: 12),
-            textColor: "#E83E3E".uiColor,
-            textAlignment: .center,
-            numberOfLines: 0
-        )
-        textLabel.isHidden = false
-        return textLabel
-    }()
-    
-    
-    lazy var upgradeVipBg: UIView = {
-        let upgradeVipBg = UIView()
-        
-        let imageView = UIImageView.createImageView(imageName: "vip_upgrade_bg",contentMode: .scaleToFill)
-        upgradeVipBg.addSubview(imageView)
-        imageView.snp.makeConstraints { make in
-            make.edges.equalToSuperview()
-        }
-        
-        let label = UILabel.createLabel(
-            text:"Free usage limit reached. Upgrade for unlimited chats.".localized,
-            font: .font(size: 14,weight: .bold),
-            textColor: "#111111".uiColor,
-            numberOfLines: 0
-        )
-        upgradeVipBg.addSubview(label)
-        label.snp.makeConstraints { make in
-            make.leading.equalTo(16)
-            make.top.equalTo(8)
-            make.bottom.equalTo(-8)
-            make.trailing.equalTo(-95)
-        }
-        
-        let upgradeBtn = UIButton.createButton(
-            title: "Upgrade".localized,
-            backgroundColor: "#111111".uiColor,
-            font:.font(size: 12,weight: .medium),
-            titleColor:.white,
-            corner: 14) { [weak self]  in
-                guard let self = self else { return }
-                TSPurchaseVC.show(target: self) { [weak self]  in
-                    guard let self = self else { return }
-                    updateVipView()
-                }
-            }
-        upgradeVipBg.addSubview(upgradeBtn)
-        upgradeBtn.snp.makeConstraints { make in
-            make.trailing.equalTo(-12)
-            make.centerY.equalToSuperview()
-            make.width.equalTo(70)
-            make.height.equalTo(28)
-        }
-        return upgradeVipBg
-    }()
-    
-    
+    lazy var vipBtn: UIButton = creatVipBtn
+    lazy var navBarView: TSBaseNavContentBarView = creatNavBarView
     
-    lazy var scrollToBottomButton: UIButton = {
-        let backBottomBtn = UIButton.createButton(image: UIImage(named: "down_arrow_line")) { [weak self]  in
-            guard let self = self else { return }
-            messagesCollectionView.scrollToLastItem(animated: false)
-        }
-        backBottomBtn.isHidden = true
-        backBottomBtn.backgroundColor = .popupColor
-        backBottomBtn.cornerRadius = 16.0
-        return backBottomBtn
-    }()
+    var deleteBlock:(()->Void)?
+
+    lazy var inputBarBgView:UIView = creatInputBarBgView
+    let inputBarTopView:UIView = UIView()
+
+    //免费次数label
+    lazy var freeText: UILabel = creatFreeText
+    lazy var upgradeVipBg: UIView = creatUpgradeVipBg
+    lazy var scrollToBottomButton: UIButton = creatScrollToBottomButton
     
     
     
@@ -140,19 +76,76 @@ class TSChatViewController: MessagesViewController, MessagesDataSource {
     override func viewDidLoad() {
         super.viewDidLoad()
         navigationItem.title = "MessageKit"
-
+        edgesForExtendedLayout = [.top]
+ 
+        // 创建轻击手势识别器
+        let tapGesture = UITapGestureRecognizer(target: self, action: #selector(clickView))
+      // 设置轻击手势识别器取消默认的视图触摸响应,避免影响子视图交互
+       tapGesture.cancelsTouchesInView = false
+      // 将轻击手势识别器添加到视图上
+        messagesCollectionView.addGestureRecognizer(tapGesture)
+        configureNaviBarView()
         configureMessageCollectionView()
         configureMessageInputBar()
         configureOtherUI()
         loadFirstMessages()
         
-        
+        vipBtn.isHidden = PurchaseManager.default.isVip
+        NotificationCenter.default.addObserver(self, selector: #selector(vipInfoChanged), name: .kPurchaseDidChanged, object: nil)
         if viewModel.uiStyle == .chat {
             // 注册通知监听,App死的时候,保存本次聊天记录到本地
             NotificationCenter.default.addObserver(self, selector: #selector(saveChatList), name: .kApplicationWillTerminate, object: nil)
+            // 监听键盘事件
+            NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
+            NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillShow(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)
+        }
+    }
+    
+    @objc func vipInfoChanged() {
+        kExecuteOnMainThread {
+            self.vipBtn.isHidden = PurchaseManager.default.isVip
+            self.updateVipView()
+        }
+    }
+    
+    @objc func clickView(){
+        view.endEditing(true)
+    }
+    
+    @objc func keyboardWillShow(_ notification: Notification) {
+
+        guard let keyboardFrame = notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? CGRect,
+              let animationDuration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? TimeInterval else {
+            return
+        }
+
+        let keyboardHeight = keyboardFrame.height
+        let contentInset = UIEdgeInsets(top: 0, left: 0, bottom: keyboardHeight, right: 0)
+
+        UIView.animate(withDuration: animationDuration) {
+            self.messagesCollectionView.contentInset = contentInset
+            self.messagesCollectionView.scrollIndicatorInsets = contentInset
+        }
+        
+        kDelayMainShort {
+            self.messagesCollectionView.scrollToLastItem(animated: false)
+        }
+    }
+
+    @objc func keyboardWillHide(_ notification: Notification) {
+        guard let animationDuration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? TimeInterval else {
+            return
+        }
+
+        let contentInset = UIEdgeInsets.zero
+
+        UIView.animate(withDuration: animationDuration) {
+            self.messagesCollectionView.contentInset = contentInset
+            self.messagesCollectionView.scrollIndicatorInsets = contentInset
         }
     }
     
+    
     @objc func saveChatList() {
         messageList.remove(at: 0)
         viewModel.updateMessages(msgModels: messageList)
@@ -179,8 +172,80 @@ class TSChatViewController: MessagesViewController, MessagesDataSource {
         
     }
     
+    public func addNormalNavBarView(){
+        navBarContentView.addSubview(normalNavBarView)
+        normalNavBarView.snp.makeConstraints { make in
+            make.edges.equalToSuperview()
+        }
+    }
+    
+    public func setTitleText(_ title: String) {
+       _ = normalNavBarView.setTitleName(NSLocalizedString(title, comment: ""))
+    }
+
+    public func setPageTitle(_ title: String) {
+        let pageTitle = title
+        let backTitle = " "
+        setTitleText(pageTitle)
+        _ = setNavigationItem(backTitle, imageName: "navi_back_white", direction: .left, action: #selector(navBarClickLeftAction))
+    }
+    @objc public func navBarClickLeftAction() {
+        debugPrint("navBarClickLeftAction -> \(type(of: self))")
+        pop()
+    }
+    
+    public func pop() {
+        if navigationController == nil {
+            dismiss(animated: true, completion: nil)
+        } else if navigationController?.presentingViewController != nil, navigationController?.viewControllers.count == 1 {
+            navigationController?.dismiss(animated: true, completion: nil)
+        } else {
+            navigationController?.popViewController(animated: true)
+        }
+    }
+    
+    public func setNavigationItem(_ name: String, imageName: String, direction: NSTextAlignment, action: Selector) -> UIButton {
+        if direction == .left {
+            return normalNavBarView.setLeftNavigationItem(name: name, imageName: imageName, target: self, action: action)
+        } else {
+            return normalNavBarView.setRightNavigationItem(name: name, imageName: imageName, target: self, action: action)
+        }
+    }
+    @objc func clickDelete(){
+        showCustomAlert(message: "Are you sure to delete".localized, deleteHandler:  { [weak self]  in
+            guard let self = self else { return }
+            viewModel.dbAIChatList.delete()
+        
+            deleteBlock?()
+            pop()
+        })
+        
+        
+    }
+    func configureNaviBarView() {
+        view.addSubview(navBarContentView)
+        navBarContentView.snp.makeConstraints { make in
+            make.leading.top.trailing.equalToSuperview()
+            make.height.equalTo(k_Nav_Height)
+        }
+        
+        if viewModel.uiStyle == .history {
+            addNormalNavBarView()
+            setPageTitle("History".localized)
+            _ = setNavigationItem("", imageName: "delete_white", direction: .right, action: #selector(clickDelete))
+        }else{
+            navBarContentView.addSubview(navBarView)
+            navBarView.snp.makeConstraints { make in
+                make.edges.equalToSuperview()
+            }
+        }
+    }
+    
+
+    
     func configureMessageCollectionView() {
-        view.backgroundColor = .clear
+        clearAndResetConstraints()
+        view.backgroundColor = .mainBg
         //设置自定义FlowLayout,itemsize等,都在这里控制
         let flowLayout = CustomMessagesFlowLayout()
         flowLayout.sectionInset = UIEdgeInsets(top: 4, left: 0, bottom: 4, right: 0)
@@ -200,6 +265,25 @@ class TSChatViewController: MessagesViewController, MessagesDataSource {
         messagesCollectionView.reloadData()
     }
     
+    
+    func clearAndResetConstraints() {
+        // 筛选出与 messagesCollectionView 相关的约束
+        let constraintsToRemove = view.constraints.filter { constraint in
+            return (constraint.firstItem as? UIView == messagesCollectionView) || (constraint.secondItem as? UIView == messagesCollectionView)
+        }
+        // 停用并移除这些约束
+        NSLayoutConstraint.deactivate(constraintsToRemove)
+        for constraint in constraintsToRemove {
+            view.removeConstraint(constraint)
+        }
+
+        
+        messagesCollectionView.snp.remakeConstraints { make in
+            make.leading.trailing.bottom.equalTo(0)
+            make.top.equalTo(k_Nav_Height)
+        }
+    }
+    
     func configureMessageInputBar() {
         
         inputBarBgView.addSubview(inputBarTopView)
@@ -499,6 +583,7 @@ extension TSChatViewController{
         
         sendMessages(data)
         messagesCollectionView.scrollToLastItem(animated: true)
+        view.endEditing(true)
     }
     
     

+ 2 - 1
AIEmoji/Business/TSTabBarController/TSTabBarController.swift

@@ -24,7 +24,8 @@ class TSTabBarController: UITabBarController {
     }
 
     @objc private func setUpData() {
-        viewControllerArray = ["TSEmojisVC", "TSGenmojiVC","TSAIChatContainerVC", "TSWallpaperVC"]
+//        viewControllerArray = ["TSEmojisVC", "TSGenmojiVC","TSAIChatContainerVC", "TSWallpaperVC"]
+        viewControllerArray = ["TSEmojisVC", "TSGenmojiVC","TSChatViewController", "TSWallpaperVC"]
         titleArray = ["Emojis","Genmoji","AIChat","Wallpaper"]
         selectedImageArray = [
             "tabbar_select_emoji",