iPhoneX适配

目录(?)[-]

  1. 核心代码
  2. 自动化修改代码
  3. 参考资料

iPhoneX适配,比较搓的一种方式,在不修改分辨率(720 x 1280)的情况下适配

iphone X 主屏尺寸: 5.8英寸 主屏分辨率: 2436 x 1125


核心代码

修改 工程目录/Classes/UnityAppController.mm 文件

判断的方式比较搓,以 iPhone X 的宽高的 与众不同来判断

为了不调整分辨率的情况下适配(这里是 竖屏 应用),高度改为 150 是最好的值。(横屏 应用修改 height 为 width,y为 x 即可)

  • 找到方法

    这里写图片描述

  • 代码

    //    _window         = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen].bounds];CGRect winSize = [UIScreen mainScreen].bounds;if (winSize.size.height / winSize.size.width > 2) {winSize.size.height -= 150;winSize.origin.y = 75;::printf("-> is iphonex hello world\n");} else {::printf("-> is not iphonex hello world\n");}_window = [[UIWindow alloc] initWithFrame: winSize];
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
  • 运行效果

    这里写图片描述


自动化修改代码

不用每次打xcode后都需要手动修改

参考:https://www.cnblogs.com/pandawuwyj/p/6904770.html

  1. 增加一个修改 文件的类

    using UnityEngine;
    using System.Collections;
    using System.Collections.Generic;
    using System.IO;namespace UnityEditor.XCodeEditor
    {public partial class XClassExt : System.IDisposable{private string filePath;public XClassExt(string fPath){filePath = fPath;if (!System.IO.File.Exists(filePath)){Debug.LogError(filePath + "not found in path.");return;}}public void WriteBelow(string below, string text){StreamReader streamReader = new StreamReader(filePath);string text_all = streamReader.ReadToEnd();streamReader.Close();int beginIndex = text_all.IndexOf(below);if (beginIndex == -1){Debug.LogError(filePath + " not found sign in " + below);return;}int endIndex = text_all.LastIndexOf("\n", beginIndex + below.Length);text_all = text_all.Substring(0, endIndex) + "\n" + text + "\n" + text_all.Substring(endIndex);StreamWriter streamWriter = new StreamWriter(filePath);streamWriter.Write(text_all);streamWriter.Close();}public void Replace(string below, string newText){StreamReader streamReader = new StreamReader(filePath);string text_all = streamReader.ReadToEnd();streamReader.Close();int beginIndex = text_all.IndexOf(below);if (beginIndex == -1){Debug.LogError(filePath + " not found sign in " + below);return;}text_all = text_all.Replace(below, newText);StreamWriter streamWriter = new StreamWriter(filePath);streamWriter.Write(text_all);streamWriter.Close();}public void Dispose(){}}
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
  2. 打包后处理,动态修改 xcode配置 及 文件内容

    using System;
    using System.IO;
    using System.Collections.Generic;
    using UnityEditor;
    using UnityEngine;
    using UnityEditor.Callbacks;#if UNITY_EDITOR_OSXusing UnityEditor.iOS.Xcode;
    using UnityEditor.XCodeEditor;#endifpublic class Package {#if UNITY_EDITOR_OSX[PostProcessBuildAttribute(100)]public static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject) {if (target != BuildTarget.iOS) {Debugger.LogWarning("Target is not iPhone. XCodePostProcess will not run");return;}// Create a new project object from build targetPBXProject project = new PBXProject();string configFilePath = PBXProject.GetPBXProjectPath(pathToBuiltProject);project.ReadFromFile(configFilePath);string targetGuid = project.TargetGuidByName("Unity-iPhone");string debug = project.BuildConfigByName(targetGuid, "Debug");string release = project.BuildConfigByName(targetGuid, "Release");project.AddBuildPropertyForConfig(debug, "CODE_SIGN_RESOURCE_RULES_PATH", "$(SDKROOT)/ResourceRules.plist");project.AddBuildPropertyForConfig(release, "CODE_SIGN_RESOURCE_RULES_PATH", "$(SDKROOT)/ResourceRules.plist");project.AddFrameworkToProject(targetGuid, "SystemConfiguration.framework", true);project.AddFrameworkToProject(targetGuid, "Security.framework", true);project.AddFrameworkToProject(targetGuid, "libz.tbd", true);project.AddFrameworkToProject(targetGuid, "libc++.tbd", true);project.SetBuildProperty(targetGuid, "ENABLE_BITCODE", "NO");project.WriteToFile(configFilePath);EditSuitIpXCode(pathToBuiltProject);}public static void EditSuitIpXCode(string path) {//插入代码//读取UnityAppController.mm文件string src = @"_window         = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen].bounds];";string dst = @"//    _window         = [[UIWindow alloc] initWithFrame: [UIScreen mainScreen].bounds];CGRect winSize = [UIScreen mainScreen].bounds;if (winSize.size.height / winSize.size.width > 2) {winSize.size.height -= 150;winSize.origin.y = 75;::printf(""-> is iphonex aaa hello world\n"");} else {::printf(""-> is not iphonex aaa hello world\n"");}_window = [[UIWindow alloc] initWithFrame: winSize];";string unityAppControllerPath = path + "/Classes/UnityAppController.mm";XClassExt UnityAppController = new XClassExt(unityAppControllerPath);UnityAppController.Replace(src, dst);}#endif}
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75


参考资料

  • http://blog.csdn.net/nicepainkiller/article/details/78926077

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/444727.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

centos安装nginx,配置负载均衡

1、安装nginx安装教程,参照:http://mp.weixin.qq.com/s/RVaRlRpHqZRjCaXGmOlfKw 2、反向代理的配置修改部署目录下conf子目录的nginx.conf文件的内容[html]view plaincopylocation / { #设置主机头和客户端真实地…

leetcode142 环形链表II

给定一个链表,返回链表开始入环的第一个节点。 如果链表无环,则返回 null。 为了表示给定链表中的环,我们使用整数 pos 来表示链表尾连接到链表中的位置(索引从 0 开始)。 如果 pos 是 -1,则在该链表中没有…

PaperNotes(18)-VectorNet- Encoding HD Maps and Agent Dynamics from Vectorized Representation

自动驾驶论文阅读笔记11. Ployline Garph2. Global Graph3. 模型目标函数4.Related work5.Experiment5.1 实验设置5.2 消融实验5.3 模型资源消耗5.4 与其他模型的对比实验VectorNet- Encoding HD Maps and Agent Dynamics from Vectorized RepresentationVectorNet: 通过矢量化…

ubuntu的apache配置https

一、配置Apache 1、开启SSL模块a2enmod ssl 2、启用SSL站点a2ensite default-ssl 3、加入监听端口vi /etc/apache2/ports.conf #编辑Apache端口配置,加入443端口 Listen 443注:Ubuntu启用SSL站点后,缺省已经加入了 (…

vim特别好的教程

欢 迎 阅 读 《 V I M 教 程 》 —— 版本 1.7 Vim 是一个具有很多命令的功能非常强大的编辑器。限于篇幅,在本教程当中 就不详细介绍了。本教程的设计目标是讲述一些必要的基本命令,而掌握好这 些命令&#x…

jquery、javascript实现(get、post两种方式)跨域解决方法

&#xfeff;&#xfeff;jquery、javascript实现(get、post两种方式)跨域解决方法一、实现get方式跨域请求数据浏览器端<script> $(document).ready(function(){$.ajax({url: "http://www.xxx.cn/index.php",type: "get",dataType: "jsonp&quo…

推荐系统(4)-逻辑回归LR、POLY2、FM、FFM

逻辑回归LR、POLY2、FM、FFM1.逻辑回归LR2.辛普森悖论3.POLY24.FM-20105.FFM6.GBDTLR-20147.LS-PLM-2017《深度学习/推荐系统》读书笔记1.逻辑回归LR Logistic Regression – 融合多种特征&#xff0c;通过sigmoid 函数&#xff0c;预测样本的被点击的概率。样本用特征向量x[x…

leetcode125验证回文串

给定一个字符串&#xff0c;验证它是否是回文串&#xff0c;只考虑字母和数字字符&#xff0c;可以忽略字母的大小写。 说明&#xff1a;本题中&#xff0c;我们将空字符串定义为有效的回文串。 示例 1: 输入: "A man, a plan, a canal: Panama" 输出: true 示例 …

配置 Elastic Beanstalk 环境负载均衡器以终止 HTTPS

&#xfeff;&#xfeff;配置 Elastic Beanstalk 环境负载均衡器以终止 HTTPS 要更新您的 AWS Elastic Beanstalk 环境以使用 HTTPS&#xff0c;您需要为您的环境中的负载均衡器配置 HTTPS 侦听器。以下两种类型的负载均衡器支持 HTTPS 侦听器&#xff1a;传统负载均衡器和应用…

AWS 给负载均衡器配置侦听器并上传IAM证书

&#xfeff;&#xfeff;1.打开EC2的负载均衡器&#xff1a;添加侦听器&#xff0c;选择https&#xff0c;ssl证书需要有一个CA证书&#xff0c;可以去阿里云申请&#xff0c;也可以从亚马逊获取&#xff1a;注意&#xff0c;这里的ssl证书要这样写其中私有密钥不是那种xxxxxx…

PaperNotes(19)-Learning Lane Graph Representations for Motion Forecasting

Learning Lane Graph Representations for Motion Forecasting1.ActorNet2.MapNet3.FusionNet4.Prediction Header5.模型参数学习自动驾驶论文阅读笔记2 Uber–ECCV2020–论文文章代码 模型的作用&#xff1a;Motion Forecasting &#xff08;这个motion都包括什么呢&#xff…

leetcode41 缺失的第一个正数

给定一个未排序的整数数组&#xff0c;找出其中没有出现的最小的正整数。 示例 1: 输入: [1,2,0] 输出: 3 示例 2: 输入: [3,4,-1,1] 输出: 2 示例 3: 输入: [7,8,9,11,12] 输出: 1 说明: 你的算法的时间复杂度应为O(n)&#xff0c;并且只能使用常数级别的空间。 思路&am…

Linux(10)-Make编译,Configure

Make编译机制,Configure1.Make机制demo1.make编译demo2.make清理demo3:make 安装demo4:make 卸载2.configure2.1 Autoconf2.2 软件的源码安装软件发布的一些基础知识。gcc, cpp, as, ld–施工队&#xff0c;底层干活工人make --包工头&#xff0c;指挥工人工作configure–分析师…

redis排行榜之日排行周排行设计

排行榜功能是一个很普遍的需求。使用 Redis 中有序集合的特性来实现排行榜是又好又快的选择。 一般排行榜都是有实效性的,比如“用户积分榜”。如果没有实效性一直按照总榜来排,可能榜首总是几个老用户,对于新用户来说,那真是太令人沮丧了。 首先,来个“今日积分榜”吧,…

Linux(11)-Ubuntu装系统

Ubuntu18.04装系统单系统双系统启动项dell 5820进不去bios。单系统 装过好多次ubuntu系统&#xff0c;每次要重装之前总是得搜索各种教程。现在总结一份简略教程如下&#xff0c;以备哪天装系统之需。 1.官网上下载Ios文件:https://ubuntu.com/download/desktop 2.找一个U盘…

最近准备学习下mongodb(一 Windows安装篇)

1 先安装mongodb 的windows版本&#xff0c;Linux的我后期会加上的。 https://www.mongodb.com/dr/fastdl.mongodb.org/win32/mongodb-win32-x86_64-2008plus-ssl-4.0.0-signed.msi/download 2.安装php扩展插件&#xff1a; https://pecl.php.net/package/mongo 根据自己的…

leetcode139 单词拆分

给定一个非空字符串 s 和一个包含非空单词列表的字典 wordDict&#xff0c;判定 s 是否可以被空格拆分为一个或多个在字典中出现的单词。 说明&#xff1a; 拆分时可以重复使用字典中的单词。 你可以假设字典中没有重复的单词。 示例 1&#xff1a; 输入: s "leetcode…

Linux(12)-Ubuntu装机后的基础应用

Ubuntu装机ssh服务器 sudo ps -e |grep ssh # 查看ssh 服务安装情况 ssh-agent--ssh客户端&#xff0c;连别人&#xff1b; sshd--ssh服务器&#xff0c; 被别人连 sudo apt-get update # 更新软件源 sudo apt-get install openssh-server # 安装ssh服务端ssh设置别…

OpenSSL编写SSL,TLS程序

一、简介:SSL(Secure Socket Layer)是netscape公司提出的主要用于web的安全通信标准,分为2.0版和3.0版.TLS(Transport Layer Security)是IETF的TLS 工作组在SSL3.0基础之上提出的安全通信标准,目前版本是1.0,即RFC2246.SSL/TLS提供的安全机制可以保证应用层数据在互联网络传输不…

PRML(3)--Chapter2(上)-概率分布-二元变量、多项式变量、高斯分布、指数族分布

PRML第二章上-概率估计2.1二元变量2.1.1 beta 分布2.2 多项式变量2.3 高斯分布2.3.1条件高斯分布、2.3.2边缘高斯分布2.3.3 高斯变量的贝叶斯定理2.3.4 高斯分布的最大似然估计2.3.5 顺序估计2.3.6 高斯分布的贝叶斯推断2.3.7 学生t分布2.3.8周期性变量2.3.9混合高斯分布2.4 指…