适配IphoneX

Posted Tearix

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了适配IphoneX相关的知识,希望对你有一定的参考价值。

先讲一下之前的分辨率适配做法:

Screen.fullScreen = true;
maxScreenWidth = Screen.currentResolution.width;
maxScreenHeight = Screen.currentResolution.height;
//基本原理是宽度适应高度,先把h搞成720,然后按屏幕比例适配w, 如果此时w/h>16/9,缩小w适配16:9
realH = 720;
realW = 720 * maxScreenWidth / maxScreenHeight;
if (maxScreenWidth / maxScreenHeight > (16/9))
{
    realW = realH * 16 / 9;
}
Sreen.SetResolution(realW, realH, true);

要适配IponeX,只需改成:

Screen.fullScreen = true;
maxScreenWidth = Screen.currentResolution.width;
maxScreenHeight = Screen.currentResolution.height;
//基本原理是宽度适应高度,先把h搞成720,然后按屏幕比例适配w, 如果此时w/h>16/9,缩小w适配16:9
realH = 720;
realW = 720 * maxScreenWidth / maxScreenHeight;
if (maxScreenWidth / maxScreenHeight > (16/9))
{
    isIphoneX = iosSdk.GetIsIphoneX();
    if (!isIphoneX)
        realW = realH * 16 / 9;
}
Sreen.SetResolution(realW, realH, true);

即,对IponeX进行全屏适配即可。

以上是关于适配IphoneX的主要内容,如果未能解决你的问题,请参考以下文章

iPhoneX 适配总结

vue适配iphoneX底部安全区域

iphonex 适配

适配IphoneX

h5 在全屏iphonex中的适配

小程序iPhonex适配