react-native - React Native - flex:1在键盘打开时不适用于ios
问题描述
我View
的风格flex: 1
包含以屏幕为中心的图像和文本框。在 android 中,当文本框聚焦并打开键盘时,视图会缩小。但是,在 ios 中,视图的大小保持不变,键盘覆盖了内容。
export default class App extends React.Component { render() {
return (
<View style={styles.container}>
<TextInput style={styles.box}/>
</View>
); }}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
padding: 8,
},
box: {
margin: 24,
fontSize: 18,
fontWeight: 'bold',
textAlign: 'center',
backgroundColor: 'red'
},
});
如上所述创建示例代码并在小吃中进行测试。在上面的代码中,为 ios 打开键盘时,文本框没有居中。
解决方案
尝试使用<keyboardavoidingview />
. 使用这个组件,一旦文本输入被聚焦,屏幕就会自动向上推。检查https://facebook.github.io/react-native/docs/keyboardavoidingview
推荐阅读
- php - 简单选择语句的参数号无效错误
- c# - 从文本文件中读取,创建数字范围,过滤掉范围外的浮点数并将最终值存储在文本文件中
- reactjs - React Native Clipboard 返回不同于控制台日志
- docker - 如何自动避免 docker mount /etc/hosts /etc/hostname /etc/resolv.conf
- php - 循环遍历php中类的每个实例
- image - 客户端(javascript)无法使用 boost beast 和 opencv 从服务器接收图像或二进制文件
- java - 当我在可绘制文件夹上导入图像并尝试使用图像视图上的图像时,应用程序崩溃。但是,当我设置图像时,该应用程序运行良好
- javascript - 如何使输入中的文本在按钮单击时进入段落
- javascript - 使用箭头键更改图像的 onkeydown 事件
- r - 如何根据另一个值对值进行分箱