码迷,mamicode.com
首页 > 其他好文 > 详细

react native获取键盘高度

时间:2017-09-06 16:43:46      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:set   ima   await   boa   move   lis   nim   mount   dshow   

componentWillUnmount() {
this.keyboardDidShowListener.remove();
this.keyboardDidHideListener.remove();
}

componentWillMount() {
this.keyboardDidShowListener = Keyboard.addListener(‘keyboardDidShow‘, this._keyboardDidShow.bind(this));
this.keyboardDidHideListener = Keyboard.addListener(‘keyboardDidHide‘, this._keyboardDidHide.bind(this));
}

_keyboardDidShow(e) {
async function run(self) {
await self.setState({
keyboardHeight: e.endCoordinates.height
});
self.refs.scroll.scrollTo({
x: 0, y: self.state.keyboardHeight, animated: true
})
}

run(this);
}

_keyboardDidHide(e) {
this.setState({
keyboardHeight: 0
})
}

react native获取键盘高度

标签:set   ima   await   boa   move   lis   nim   mount   dshow   

原文地址:http://www.cnblogs.com/dragonh/p/7485553.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!