我对通用应用程序中的图像命名约定有疑问,尤其是 ipad mini。
我正在开发一个跨 iphone 4s、ipad 3(即 ipad with retina)和 ipad mini 的通用应用程序。我有一张图片,我想将其作为背景加载到应用程序中。我正在使用
[UIImage imageNamed:@"background"]
获取图像。这适用于 iphone 和 ipad,但不适用于 ipad mini。
为了调试,我使用了
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"background" ofType:@"png"];
NSLog(@"background image: %@",filePath);
确保选择了正确的图像。在 iPad 上我得到
background image: /var/mobile/Applications/[...RESOURCEPATH...]/background.png
在 iphone 上我得到
background image: /var/mobile/Applications/[...RESOURCEPATH...]/background~iphone.png
但是在 ipad mini 上我得到了
background image: (null)
真正奇怪的是,我包含了图像的命名版本:
background~iphone.png
background@2x~iphone
background-Portrait~ipad
background-Portrait@2x~ipad
但不是 background.png 本身。
当我意识到这个错误时,我添加了 background.png 图片,现在我的背景也出现在 mini 上了。
这是怎么回事,正确的做法是什么?
最佳答案
图像名称中唯一会看到“修饰符”(如“-PortraitUpsideDown
”)的地方是启动图像,如 this Apple documentation (look in the "Providing Launch Images for Different Orientations" section) 中所述。 .
您真的应该只有两个背景图像。一种用于常规分辨率,一种用于 Retina 分辨率(即“@2x
”后缀)。这两张图片应该能够很好地处理旋转。
关于ios - ipad mini 的图像命名约定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16492008/