應(yīng)用場(chǎng)景:
前段時(shí)間公司開(kāi)發(fā)一個(gè)新項(xiàng)目,要求在各個(gè)設(shè)備上均顯示一致答倡,老大要求純代碼開(kāi)發(fā),嘗試使用第三方庫(kù)masonry開(kāi)發(fā),但效果是不是很好肛鹏,無(wú)法滿足需求遏弱。后來(lái)通過(guò)查找資料得到可以通過(guò)如下的圖建立聯(lián)系找到解決方法
代碼如下:
/**
* 1080*1920轉(zhuǎn)6的系數(shù)
*/
static CGFloat const parameterOne =0.96;
/**
* 6轉(zhuǎn)5的系數(shù)
*/
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 ;
}