detail.vue
onLoad() {
var wv = plus.webview.create("","custom-webview",{
'uni-app': 'none', //不加载uni-app渲染层框架,避免样式冲突
})
wv.loadURL("/hybrid/html/index.html")
var currentWebview = this.$scope.$getAppWebview();
currentWebview.append(wv);
}
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title></title>
</head>
<body>
<p><br></p<p><br></p><p><br></p>
<input type="text" />
<script>
document.addEventListener("plusready", onPlusReady, false);
function onPlusReady(){
document.addEventListener("keyboardchange", onKeyboardChange, false);
}
function onKeyboardChange(e){
var height = e.height; // 键盘高度
console.log('键盘高度:'+height)
if(height > 0){
console.log('键盘显示');
}else{
console.log('键盘隐藏');
}
}
</script>
</body>
</html>
onPlusReady是走进去的,onKeyboardChange没有走进去,不知道是哪里配置没写对,还是其他原因,求解决方法!
1 个回复
4***@qq.com (作者)
我知道原因了,自问自答吧。
plus.webview.create() 创建的weview是子weview,软键盘其实是在主weview的(detail.vue),所以在子weview监听keyboardchange肯定不行, 只能在主weview监听,然后根据软键盘高度改变子weview的高度:
子weview注册window.onresize,来接收软键盘的高度变化, 只是无法直接获得软键盘的高度,而是用了变通的办法,不知道还有其他办法没,等回复。。。