美文网首页
2019-08-19 iPhone X 适配

2019-08-19 iPhone X 适配

作者: 多肉散散步 | 来源:发表于2019-08-19 11:15 被阅读0次
    1.获取状态栏的高度
    let statusBarHeight = UIApplication.shared.statusBarFrame.height;
    

    使用公共的文件宏定义,用于屏幕适配:

    let statusBarHeight = UIApplication.shared.statusBarFrame.height;
    //导航栏高度
    let navigationHeight = (statusBarHeight + 44)
    //tabbar高度
    let tabBarHeight = (statusBarHeight == 44 ? 83 : 49)
    //顶部的安全距离
    let topSafeAreaHeight = (statusBarHeight - 20)
    //底部的安全距离
    let bottomSafeAreaHeight = (tabBarHeight - 49) 
    
    2.获取底部的底部的安全距离

    iPhone X手机为34,iPhone X以前手机为0

    let bottomSafeAreaHeight = UIApplication.shared.windows.last?.safeAreaInsets.bottom ?? 0.0;
    

    使用公共的文件宏定义,用于屏幕适配:

    //底部的安全距离
    let bottomSafeAreaHeight = UIApplication.shared.windows.first?.safeAreaInsets.bottom ?? 0.0
    //顶部的安全距离
    let topSafeAreaHeight = (bottomSafeAreaHeight == 0 ? 0 : 24)
    //状态栏高度
    let statusBarHeight = UIApplication.shared.statusBarFrame.height;
    //导航栏高度
    let navigationHeight = (bottomSafeAreaHeight == 0 ? 64 : 88)
    //tabbar高度
    let tabBarHeight = (bottomSafeAreaHeight + 49) 
    

    相关文章

      网友评论

          本文标题:2019-08-19 iPhone X 适配

          本文链接:https://www.haomeiwen.com/subject/docssctx.html