美文网首页
iPhone设备适配(更新中·····)

iPhone设备适配(更新中·····)

作者: 小弱鸡 | 来源:发表于2016-07-13 11:38 被阅读47次

应用场景:

前段时间公司开发一个新项目,要求在各个设备上均显示一致,老大要求纯代码开发,尝试使用第三方库masonry开发,但效果是不是很好,无法满足需求。后来通过查找资料得到可以通过如下的图建立联系找到解决方法


设备逻辑尺寸和像素关系示意图.png
代码如下:
/**
*  1080*1920转6的系数
*/
static CGFloat  const parameterOne =0.96;
/**
*  6转5的系数
*/
static CGFloat  const parametertwo =1.171875;
static CGFloat  const parameterThree =1.15;


+ (CGFloat)adaptionFrom:(CGFloat)pixel{
   CGFloat chanagePixel;
if ([UIScreen mainScreen].bounds.size.width ==320) {
           if ([UIScreen mainScreen].bounds.size.height ==480) {
               
           }else if ([UIScreen mainScreen].bounds.size.height ==568){
           return    chanagePixel  =  pixel/parameterOne/3*2/parametertwo/2;
           }
       }else if ([UIScreen mainScreen].bounds.size.width ==375){
        return   chanagePixel  =  pixel/parameterOne/3;
       }else if ([UIScreen mainScreen].bounds.size.width ==414){
        return   chanagePixel  =  pixel*parameterThree/3;
       }
return 0 ;
}
缺点:粗略方法、计算次数过多,需要一个恒定定参数,后期优化,不支持4s等

相关文章

网友评论

      本文标题:iPhone设备适配(更新中·····)

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