gpt4 book ai didi

ios - 在 react-native 中打开键盘时,ScrollView 无法滚动到底部。 [IOS]

转载 作者:行者123 更新时间:2023-12-04 03:41:15 30 4
gpt4 key购买 nike

当键盘关闭时,ScrollView工作正常。但是当键盘打开时,它不会滚动到底部。不过,它在 Android 中运行良好。问题仅与iOS有关。
如果我使用 react-native-keyboard-aware-scroll-view ,那么问题解决了,但我不想使用这个包。
我的工作环境:-
博览会 SDK :- 40
平台:- IOS

import React from "react";
import {
ScrollView,
TextInput,
SafeAreaView,
TouchableOpacity,
Text,
} from "react-native";

function App() {
return (
<SafeAreaView style={{ flex: 1 }}>
<ScrollView style={{ flex: 1 }}>
<TextInput style={{ borderWidth: 2, height: 50, marginVertical: 10 }} />
<TextInput style={{ borderWidth: 2, height: 50, marginVertical: 10 }} />
<TextInput style={{ borderWidth: 2, height: 50, marginVertical: 10 }} />
<TextInput style={{ borderWidth: 2, height: 50, marginVertical: 10 }} />
<TextInput style={{ borderWidth: 2, height: 50, marginVertical: 10 }} />
<TextInput style={{ borderWidth: 2, height: 50, marginVertical: 10 }} />
<TextInput style={{ borderWidth: 2, height: 50, marginVertical: 10 }} />
<TextInput style={{ borderWidth: 2, height: 50, marginVertical: 10 }} />
<TextInput style={{ borderWidth: 2, height: 50, marginVertical: 10 }} />
<TextInput style={{ borderWidth: 2, height: 50, marginVertical: 10 }} />
<TextInput style={{ borderWidth: 2, height: 50, marginVertical: 10 }} />
<TextInput style={{ borderWidth: 2, height: 50, marginVertical: 10 }} />
<TextInput style={{ borderWidth: 2, height: 50, marginVertical: 10 }} />
<TextInput style={{ borderWidth: 2, height: 50, marginVertical: 10 }} />
<TouchableOpacity
style={{ height: 50, backgroundColor: "red", marginVertical: 10 }}
>
<Text>Button</Text>
</TouchableOpacity>
</ScrollView>
</SafeAreaView>
);
}

export default App;

最佳答案

您可以像这样使用 KeyboardAwareScrollView 代替:

<KeyboardAwareScrollView  keyboardShouldPersistTaps={'always'}
style={{flex:1}}
showsVerticalScrollIndicator={false}>
{/* Your code goes here*/}
</KeyboardAwareScrollView>
还有一些你可以做的额外的事情,我使用样式表而不是每次都添加文本输入的样式,这是一个例子:
import {StyleSheet} from 'react-native

function App() {
return (
<SafeAreaView style={{ flex: 1 }}>
<TextInput style={styles.textInput} />
<TextInput style={styles.textInput} />
<TextInput style={styles.textInput} />
</SafeAreaView>
);
}


const styles = StyleSheet.create({
textInput: {
borderWidth: 2,
height: 50,
marginVertical: 10
});
如果你想了解更多关于 KeyboardAwareScrollView 你可以去这里:
https://github.com/APSL/react-native-keyboard-aware-scroll-view
以及更多关于样式表的信息:
https://reactnative.dev/docs/stylesheet

关于ios - 在 react-native 中打开键盘时,ScrollView 无法滚动到底部。 [IOS],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65987405/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com