From 20b8fb239795b2d1ffe1ebb061a041215da010df Mon Sep 17 00:00:00 2001 From: xsx <825657193@qq.com> Date: Thu, 21 Aug 2025 10:59:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20ios=E9=A1=B5=E9=9D=A2=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E6=BB=9A=E5=8A=A8=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- im-uniapp/pages/chat/chat-box.vue | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/im-uniapp/pages/chat/chat-box.vue b/im-uniapp/pages/chat/chat-box.vue index 9613af5..9507d4a 100644 --- a/im-uniapp/pages/chat/chat-box.vue +++ b/im-uniapp/pages/chat/chat-box.vue @@ -866,12 +866,13 @@ export default { return; } if (uni.getSystemInfoSync().platform == 'ios') { - // ios h5实现键盘监听 - window.addEventListener('focusin', this.focusInListener); - window.addEventListener('focusout', this.focusOutListener); // 监听键盘高度,ios13以上开始支持 if (window.visualViewport) { window.visualViewport.addEventListener('resize', this.resizeListener); + } else { + // ios h5实现键盘监听 + window.addEventListener('focusin', this.focusInListener); + window.addEventListener('focusout', this.focusOutListener); } } else { // 安卓h5实现键盘监听 @@ -885,9 +886,12 @@ export default { }, unListenKeyboard() { // #ifdef H5 - window.removeEventListener('resize', this.resizeListener); window.removeEventListener('focusin', this.focusInListener); window.removeEventListener('focusout', this.focusOutListener); + window.removeEventListener('resize', this.resizeListener); + if (window.visualViewport) { + window.visualViewport.removeEventListener('resize', this.resizeListener); + } // #endif // #ifndef H5 uni.offKeyboardHeightChange(this.keyBoardListener); @@ -906,12 +910,14 @@ export default { if (window.visualViewport && uni.getSystemInfoSync().platform == 'ios') { keyboardHeight = this.initHeight - window.visualViewport.height; } - console.log("resizeListener:", window.visualViewport.height) - this.isShowKeyBoard = keyboardHeight > 150; - if (this.isShowKeyBoard) { + let isShowKeyBoard = keyboardHeight > 150; + if (isShowKeyBoard) { this.keyboardHeight = keyboardHeight; } - setTimeout(() => this.reCalChatMainHeight(), 30); + if (this.isShowKeyBoard != isShowKeyBoard) { + this.isShowKeyBoard = isShowKeyBoard; + setTimeout(() => this.reCalChatMainHeight(), 30); + } }, focusInListener() { this.isShowKeyBoard = true;