Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
407 views
in Technique[技术] by (71.8m points)

uniapp中为什么获取到的高度和键盘的高度会每次都一样。

这个问题查了多久,也咨询了很多人,目前得到的结果是说,uniapp 中的这个方法有BUG,目前无解。

`//监听评论框

    onLoad(){
        uni.getSystemInfo({
            success:  (res) => {     
                this.setHeight = res.windowHeight-uni.upx2px(100) 
            //当前屏幕高度    
            console.log(res.windowHeight)
             }
        
        }),
        uni.onKeyboardHeightChange(res =>{
        //获取键盘高度
            this.Keyboard=res.height;

        }),
        
    
    },
    watch: {
                Keyboard(newValue){
                    this.height=this.setHeight-newValue
                }
    },    ~~~~
    `
    用上面方法获取屏幕高度,和键盘高度,让两者相减得出当前文本框的高度,可是为什么获取到的高度会有变化,有时是好的,有时就会超出当前高度,文本框就会被键盘档到。

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

你试试在评论框的focus事件中,获取键盘高度


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...