Skip to content
This repository has been archived by the owner on Apr 29, 2021. It is now read-only.

切scene後,獲取虛擬鍵盤高度值為零 #430

Open
MingBow opened this issue May 28, 2020 · 2 comments
Open

切scene後,獲取虛擬鍵盤高度值為零 #430

MingBow opened this issue May 28, 2020 · 2 comments
Labels
good first issue Good for newcomers

Comments

@MingBow
Copy link

MingBow commented May 28, 2020

個人測試中使用了兩個scene做場景的切換,scene1跟scene2,
scene1跟scene2各擺放一個按鈕做場景切換,
並在scene1最下方,另外擺放了uiwidgets的TextField widget做獲取虛擬鍵盤高度測試,
另外我想要在場景切換時TextField不被destroy,
所以使用了DontDestroyOnLoad讓TextField一直保持存在,
當我啟動程式時,預設為scene1,
這時點擊TextField時可獲取虛擬鍵盤高度,並把TextField往上推,
關閉虛擬鍵盤時,TextField會回到原位,
這時再點擊切換場景按鈕,切換到scene2,
此時點擊TextField並獲取虛擬鍵盤高度值為零(有印log),
我是使用MediaQuery.of(this.context).viewInsets.bottom來獲取虛擬鍵盤高度。
只要切過scene後,MediaQuery.of(this.context).viewInsets.bottom取得的值都會是零,
不知有何方式可解決?

@zhuxingwei
Copy link
Contributor

Hi 您好,多谢您的反馈!看起来可能和DontDestroyOnLoad有关,我们先查一下再给您反馈!

@MingBow
Copy link
Author

MingBow commented Jun 19, 2020

關於這問題,我後來發現uiwidgets會建一個__UIWidgetsMessageManager在場景中,在切場景時會被刪除,後來我的作法是也把__UIWidgetsMessageManager加入到DontDestroyOnLoad來解決。

@zhuxingwei zhuxingwei added the good first issue Good for newcomers label Jun 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants