我正在尝试在启动时在我的应用程序中显示的第一个视图显示背景图像,该图像与 LaunchImage 显示的图像相同。
我已经正确设置了 LaunchImage 资产目录,并且它在启动时正确显示。我正在使用 iPad 模拟器并将其设置为横向。
但是,我的背景图像不仅方向错误,而且尺寸错误。
考虑以下代码......
[self.backgroundImageView setImage:[UIImage imageNamed:@"LaunchImage"]];
NSLog(@"Image size should be: %@", [[UIScreen mainScreen] scale] == 1 ? @"1024x768":@"2048x1136");
NSLog(@"Image size is:%@", NSStringFromCGSize(self.backgroundImageView.image.size));
第一个 NSLog 正确地声明了 1024x768。
然而,第二个 NSLog 状态为 320x480。这只是资产目录中的第一张图片,即 iPhone LaunchImage。
这里有什么想法吗?
更新:
我在网上看到了很多关于图像命名约定的答案,下面的第一个答案足以列出所有这些。对于任何需要这些的人来说,这是一个很棒的清单。
但是,资产目录的重点是存储每个设备的所有图像,iOS6 或 7,视网膜与否,以及用于哪个方向。如果每次显示图像时仍然需要检查什么设备、方向、是否是视网膜,那么资产目录的意义何在?我认为这是他们的原因之一。
我应该注意到,这是我希望过去在我的应用程序中工作的。然后我更改了资产目录中的图像,一切仍在工作。但是,我决定将图像改回原始图像,这就是一切都破裂的地方。我已经尝试清理构建,甚至删除派生数据并重新启动 xCode。不去。
我在可用的资产目录中有正确的文件。但是,您会注意到,正如您所期望的那样,它们并没有按照 Alexander Kostiev 的回答中所述的文件名保存。相反,它们以其中的尺寸命名。但是它们在 json 中被正确引用,因为我将在接下来发布...
{
"images" : [
{
"orientation" : "portrait",
"idiom" : "iphone",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"filename" : "AppImage@2x320x480.png",
"scale" : "2x"
},
{
"extent" : "full-screen",
"idiom" : "iphone",
"subtype" : "retina4",
"filename" : "AppImage@2x320x568.png",
"minimum-system-version" : "7.0",
"orientation" : "portrait",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "ipad",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"filename" : "AppImage768x1024.png",
"scale" : "1x"
},
{
"orientation" : "landscape",
"idiom" : "ipad",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"filename" : "AppImage1024x768.png",
"scale" : "1x"
},
{
"orientation" : "portrait",
"idiom" : "ipad",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"filename" : "AppImage@2x768x1024.png",
"scale" : "2x"
},
{
"orientation" : "landscape",
"idiom" : "ipad",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"filename" : "AppImage@2x1024x768.png",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "iphone",
"extent" : "full-screen",
"filename" : "AppImage320x480.png",
"scale" : "1x"
},
{
"orientation" : "portrait",
"idiom" : "iphone",
"extent" : "full-screen",
"filename" : "AppImage@2x320x480-1.png",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "iphone",
"extent" : "full-screen",
"filename" : "AppImage@2x320x568-1.png",
"subtype" : "retina4",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "ipad",
"extent" : "to-status-bar",
"filename" : "AppImage768x1004.png",
"scale" : "1x"
},
{
"orientation" : "landscape",
"idiom" : "ipad",
"extent" : "to-status-bar",
"filename" : "AppImage1024x748.png",
"scale" : "1x"
},
{
"orientation" : "portrait",
"idiom" : "ipad",
"extent" : "to-status-bar",
"filename" : "AppImage@2x768x1004.png",
"scale" : "2x"
},
{
"orientation" : "landscape",
"idiom" : "ipad",
"extent" : "to-status-bar",
"filename" : "AppImage@2x1024x748.png",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
正如您在顶部的第四项中看到的那样,是 iPad 的 json,在纵向布局中没有视网膜显示。我已确认此文件存在于资产目录目录中,并且它实际上是我在预览中查看的正确图像。
还有什么想法吗?
更新 2:
我现在也尝试添加名为 background-Landscape~ipad.png 和 background-Portrait~ipad.png 的文件。我现在使用以下内容加载图像...
[self.backgroundImageView setImage:[UIImage imageNamed:@"background"]];
我试过背景和背景.png。但是没有显示图像,并且 image.size 为 0,0。IE。UIImage imageNamed 给了我一个零图像。
我现在完全不知所措。