适配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进行全屏适配即可。

posted @ 2017-11-08 21:38  BigTreee  阅读(394)  评论(0编辑  收藏  举报