提交 5ab3890f 编写于 作者: DCloud-yyl's avatar DCloud-yyl

示例input框通过代码控制不被软键盘遮挡兼容多种场景

上级 9cc78901
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
</list-view> </list-view>
<web-view v-if="indexView==2" src="/hybrid/html/local.html" id="webv" style="height:380px"></web-view> <web-view v-if="indexView==2" src="/hybrid/html/local.html" id="webv" style="height:380px"></web-view>
<view style="position:relative;background-color:white;" :style="{bottom: inputBottom}"> <view style="position:relative;background-color:white;" :style="{bottom: inputBottom}">
<input placeholder="滚动视图外的居底输入框" adjust-position="false" @focus="onInputFocus" @blur="onInputBlur" /> <input placeholder="滚动视图外的居底输入框" adjust-position="false" @blur="onInputBlur" @keyboardheightchange="onInputKeyboardChange" />
</view> </view>
</view> </view>
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
isLeft: false, isLeft: false,
navigationBarTextColor: '#000', navigationBarTextColor: '#000',
indexView: 0, indexView: 0,
windowHeight: 0,
inputBottom: '0px' inputBottom: '0px'
} }
}, },
...@@ -100,12 +101,15 @@ ...@@ -100,12 +101,15 @@
ChangeView(e:UniRadioGroupChangeEvent){ ChangeView(e:UniRadioGroupChangeEvent){
this.indexView = parseInt(e.detail.value) this.indexView = parseInt(e.detail.value)
}, },
onInputFocus(e:UniInputFocusEvent ) { onInputBlur(_:UniInputBlurEvent) {
this.inputBottom = `${e.detail.height}px`;
},
onInputBlur(e:UniInputBlurEvent) {
this.inputBottom = '0px'; this.inputBottom = '0px';
}, },
onInputKeyboardChange(e:UniInputKeyboardHeightChangeEvent) {
let inputBottom = e.target?.getBoundingClientRect()?.bottom??this.windowHeight;
let remainHeight = this.windowHeight - inputBottom;
let bottom = (remainHeight > e.detail.height)?0:(e.detail.height-remainHeight);
this.inputBottom = `${bottom}px`;
},
// 自动化测试 // 自动化测试
getLifeCycleNum() : number { getLifeCycleNum() : number {
return state.lifeCycleNum return state.lifeCycleNum
...@@ -114,6 +118,12 @@ ...@@ -114,6 +118,12 @@
setLifeCycleNum(num : number) { setLifeCycleNum(num : number) {
setLifeCycleNum(num) setLifeCycleNum(num)
}, },
},
onReady() {
this.windowHeight = uni.getWindowInfo().windowHeight;
},
onResize() {
this.windowHeight = uni.getWindowInfo().windowHeight;
} }
} }
</script> </script>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册