【发布时间】:2017-12-30 16:05:00
【问题描述】:
我正在尝试使用TextInput 输入一个值,但键盘挡住了视图。我使用填充配置了 KeyboardAvoidingView,因此当键盘处于活动状态时元素被向上推,但我的输入字段仍然被键盘完全阻止。我尝试为整个渲染方法创建一个父视图,并用 KeyboardAvoidingView 包装我的子视图,但这也不起作用。屏幕截图显示了该行为。
在 iOS 模拟器上测试。
return (
<KeyboardAvoidingView behavior='padding'>
<View>
<View style={styles.container}>
<View style={styles.header}>
{jsonData}
<TouchableHighlight
underlayColor='transparent'
style={styles.btn}
onPress={this.goToAcibtnTwo}>
<Image source={images.prredbtn}></Image>
</TouchableHighlight>
<Text style={styles.textthingsmall}>{'Must be Paid Immediately'}</Text>
{jsonData2}
<TouchableHighlight
underlayColor='transparent'
style={styles.btn}
onPress={this.goToAcibtnTwo}>
<Image source={images.prgreenbtn}></Image>
</TouchableHighlight>
<Text style={styles.textthingsmall}>{'May include next payment or other fees'}</Text>
{jsonData3}
<TouchableHighlight
underlayColor='transparent'
style={styles.btn}
onPress={this.goToAcibtnTwo}>
<Image source={images.prgreenbtn}></Image>
</TouchableHighlight>
{jsonData4}
<View
style={{
flexDirection: 'row',
paddingBottom: 15
}}>
<TouchableHighlight
underlayColor='transparent'
style={styles.btn}
onPress={this.goToAcibtnTwo}>
<Image source={images.prgreenbtn}></Image>
</TouchableHighlight>
<TextInput
style={{
borderColor: 'white',
borderWidth: 2,
height: 40,
width: 100,
fontSize: 17,
marginLeft: 60,
justifyContent: 'center',
alignSelf: 'center',
color: 'white'
}}
keyboardType='numeric'
placeholder='0.00'
returnKeyType="done"
maxLength={10}
placeholderTextColor='ghostwhite'
onChangeText={(valueMoney) => this.setState({valueMoney})}
value={this.state.valueMoney}
onEndEditing={this.formatedMoneyEnd}/>
</View>
</View>
<View>
<Image style={styles.btmicons} source={images.optionsroundbtn}/>
</View>
</View>
</View>
</KeyboardAvoidingView>
);
}
}
export default Profile;
这是 CSS
header: {
alignSelf: 'center',
height: window.height * 0.7,
backgroundColor: '#0450A1',
width: 400
},
bottom: {
alignSelf: 'center',
width: 400
},
btmicons: {
flexDirection: 'column'
},
headerthing: {
flex: 1,
alignItems: 'center',
paddingTop: 10
},
textthing: {
alignSelf: 'flex-start',
paddingLeft: 35,
fontFamily: 'SFProText-Regular',
fontSize: 17,
color: '#FFFFFF',
flexDirection: 'row'
},
textthingsmall: {
alignSelf: 'flex-start',
paddingLeft: 35,
fontFamily: 'SFProText-Regular',
fontSize: 12,
paddingTop: 3,
color: '#FFFFFF',
flexDirection: 'row'
},
numberthing: {
alignSelf: 'flex-end',
paddingRight: 10,
fontFamily: 'SFProText-Regular',
fontSize: 35,
color: '#FFFFFF'
},
headerthing2: {
alignItems: 'center',
flex: 1,
padding: 1
},
separator: {
alignSelf: 'center'
},
btn: {
alignSelf: 'flex-start',
paddingLeft: 35,
marginBottom: 0,
paddingBottom: 0
},
headerthing3: {
alignItems: 'center',
flex: 1,
flexDirection: 'row'
},
rowLabelnum: {
fontFamily: 'PTSans-Regular',
fontSize: 24,
color: '#FFFFFF'
},
rowLabelnummain: {
fontFamily: 'PTSans-Regular',
fontSize: 36,
color: '#FFFFFF',
alignSelf: 'center'
},
rowLabelText: {
fontFamily: 'PTSans-Bold',
fontSize: 24,
color: '#FFFFFF'
},
rowLabelTextmain: {
fontFamily: 'PTSans-Bold',
fontSize: 30,
color: '#FFFFFF'
},
rowLabelnumbtn: {
fontFamily: 'PTSans-Regular',
fontSize: 20,
color: '#252525'
},
rowLabelTextbtn: {
fontFamily: 'PTSans-Bold',
fontSize: 25,
color: '#252525'
},
separate: {
alignSelf: 'center',
justifyContent: 'center',
width: 2,
height: 100,
backgroundColor: '#FFFFFF',
marginBottom: 20
},
content: {
flexDirection: 'row',
alignSelf: 'center',
justifyContent: 'center',
width: 357,
height: 2,
backgroundColor: '#FFFFFF',
marginBottom: 30
},
rectangleTop: {
marginTop: 80,
padding: 2
},
rectangleText: {
flex: 1,
flexDirection: 'row'
},
rectangleleft: {
flexDirection: 'row',
alignSelf: 'center',
justifyContent: 'center'
},
keyboardview: {
justifyContent: 'center',
paddingHorizontal: 20,
paddingTop: 20
}
【问题讨论】:
-
您好,您已将“behavior={'padding'}”此属性赋予 View,这不是 KeyboarAvoidingView 的属性的 View 属性。因此请尝试将该属性赋予 KeyboarAvoidingView。谢谢
-
这实际上是一个编辑错误。具有填充行为的视图曾经是 KeyboardAvoidingView 但我在 SO 中发布时忘记删除它。
标签: ios reactjs react-native jsx