所以,我正在制作一个应用程序,其中包含大量用于 UI 的图像,但我在尝试设置框架时遇到了 @1x、2x 和 3x 概念的问题。
所以首先,我编写了一个全局函数库,其中包含一个名为的函数,getDevice
这样我就可以确定用户使用什么设备来为每个元素设置正确的帧:
//Device
+ (int)getDevice
{
CGSize bounds = [[UIScreen mainScreen] bounds].size;
if((bounds.width == 320 && bounds.height == 480) || (bounds.width == 480 && bounds.height == 320))
return gDevice_iPhone4S;
else if((bounds.width == 320 && bounds.height == 568) || (bounds.width == 568 && bounds.height == 320))
return gDevice_iPhone5;
else if((bounds.width == 375 && bounds.height == 667) || (bounds.width == 667 && bounds.height == 375))
return gDevice_iPhone6;
else if((bounds.width == 414 && bounds.height == 736) || (bounds.width == 736 && bounds.height == 414))
return gDevice_iPhone6Plus;
else if((bounds.width == 768 && bounds.height == 1024) || (bounds.width == 1024 && bounds.height == 768))
return gDevice_iPad;
return gDevice_Unknown;
}
这一切都运行良好,但我的问题是围绕框架大小,现在我可以识别正确的设备。例如,假设我有三个按钮,我想跨越屏幕底部。在 iPhone 4S 上,它会是这样的:
现在这是使用 3 张图片:
- image_1@2x.png (220x80)
- image_2@2x.png (200x80)
- image_3@2x.png (220x80)
但是当我想在 iPhone 6 上使用这些图像时会发生什么?
现在这应该使用相同的图像,对吧,因为 iPhone 6 仍然使用@2x?
- image_1@2x.png (220x80) -> (258x94)
但随后(220x80)
需要成为(258x94)
这将拉伸图像。那么当我需要@1x、@2x、@iPhone62x 和@iPhone6Plus3x 时,拥有@1x、@2x 和@3x iPhone 图像有什么意义呢?