![](/img/trans.png)
[英]How to move up all component on screen when open keyboard in React Native?
[英]How to move a view when the keyboard shows up in React Native?
當 TextInput 成為焦點時,鍵盤會隱藏提交按鈕。 如何在 TextInput 下方自動滑動組件
現在使用 react-native KeyboardAvoidingView 怎么樣( 官方文檔)
import {KeyboardAvoidingView} from 'react-native';
<KeyboardAvoidingView style={styles.container} behavior="padding" enabled>
... your UI ...
</KeyboardAvoidingView>;
在 iOS 上測試,對我來說開箱即用。 對於 android 考慮添加參數: android:windowSoftInputMode="adjustResize"
到你的 AndroidManifest.xml
我遇到了同樣的問題,想在鍵盤出現時移動內容。
我通過使用類似問題的最后一個答案解決了它:
當 TextInput 有焦點時,如何將窗口從鍵盤后面自動滑出?
您基本上使用鍵盤的事件偵聽器並相應地調整內容。 但是請注意,iOS 和 Android 之間的偵聽器不同。 Android 僅支持 keyboardDidShow 和 keyboardDidHide,而 iOS 也支持 keyboardWillShow 和 keyboardWillHide。
希望有幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.