欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

如何在uniapp中獲取可視區(qū)域的高度(uni.getSystemInfo)

 更新時間:2023年04月06日 10:43:11   作者:打工仔小白  
這篇文章主要給大家介紹了關于如何在uniapp中獲取可視區(qū)域的高度(uni.getSystemInfo)的相關資料,文中通過圖文以及實例代碼介紹的非常詳細,對大家學習或者使用uniapp具有一定的參考學習價值,需要的朋友可以參考下

前言

在實際開發(fā)中我們會遇到不確定高度的情況,那么在uniapp中我們?nèi)绾潍@取區(qū)域的高度吶?一起來看看吧

使用到的:

uni-app提供了異步(uni.getSystemInfo)和同步(uni.getSystemInfoSync)的2個API獲取系統(tǒng)信息

uni.getSystemInfo(OBJECT)

異步獲取系統(tǒng)信息

OBJECT 參數(shù)說明:

參數(shù)名

類型

必填

說明

success

Function

接口調(diào)用成功的回調(diào)

fail

Function

接口調(diào)用失敗的回調(diào)函數(shù)

complete

Function

接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會執(zhí)行)

success 返回參數(shù)說明,目前需要使用到的:

參數(shù)

說明

windowHeight

可使用窗口高度

statusBarHeight

手機狀態(tài)欄的高度

一、分析uniapp的可視區(qū)域

是哪塊哪?其實和我們想的有些出入

其實就是藍色區(qū)域=紅色區(qū)域-綠色區(qū)域

代碼:

 getClineHeight(){
     const res = uni.getSystemInfo({
           success:(res=>{
                  this.clientHeight = res.windowHeight-uni.upx2px(80)
            })
        });
     },

tip:注意,在我們的微信小程序中是可以正確顯示的,但是在ios中是有問題的

二、如何在小程序和ios中都能正確顯示

我們只需要獲取系統(tǒng)信息中的platform信息,判斷是ios或者android或者其他

tip注意點:

1.注意這里的單位是pxname我們需要將代碼中導航欄寫的css的80rpx轉(zhuǎn)換為40px,使用upx2px直接可以進行轉(zhuǎn)換

2.ios本身有44的高度,Android是48

代碼:

        getBarHeight(){
                const res = uni.getSystemInfoSync()
                if(res.platform==='ios'){
                    return 44+res.statusBarHeight
                }else if(res.platform==='android'){
                    return 48+res.statusBarHeight
                }else{
                    return 0;
                }
            },
            //獲取可視區(qū)域高度
            getClineHeight(){
                const res = uni.getSystemInfo({
                    success:(res=>{
                        this.clientHeight = res.windowHeight-uni.upx2px(80)-this.getBarHeight();
                    })
                });
            },

三、減掉的部分

白色部分=綠色部分(windowHeight)-藍色部分(ios44,Android48)-橙色部分(getSystemInfoSync中的statusBarHeight)-黑色部分(你設置的高度或者使用組件的高度,注意單位是px)

windowHeight

可使用窗口高度

windowHeight

可使用窗口高度

減去

代碼:

        getBarHeight(){
                const res = uni.getSystemInfoSync()
                if(res.platform==='ios'){
                    return 44+res.statusBarHeight
                }else if(res.platform==='android'){
                    return 48+res.statusBarHeight
                }else{
                    return 0;
                }
            },
            //獲取可視區(qū)域高度
            getClineHeight(){
                const res = uni.getSystemInfo({
                    success:(res=>{
                        this.clientHeight = res.windowHeight-uni.upx2px(80)-this.getBarHeight();
                    })
                });
            },

總結(jié)

到此這篇關于如何在uniapp中獲取可視區(qū)域的高度(uni.getSystemInfo)的文章就介紹到這了,更多相關uniapp獲取可視區(qū)域的高度內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論