Ios 基于设备和方向的资产目录UIImage大小不正确

Ios 基于设备和方向的资产目录UIImage大小不正确,ios,objective-c,uiimage,orientation,asset-catalog,Ios,Objective C,Uiimage,Orientation,Asset Catalog,我试图在启动时在应用程序中显示的第一个视图中显示背景图像,该图像与启动图像显示的图像相同 我正确设置了LaunchImage资产目录,并在启动时正确显示。我用的是iPad模拟器,它是横向的 然而,我的背景图像不仅方向不对,而且大小也不对 考虑以下代码位 [self.backgroundImageView setImage:[UIImage imageNamed:@"LaunchImage"]]; NSLog(@"Image size should be: %@", [[UIScreen mai

我试图在启动时在应用程序中显示的第一个视图中显示背景图像,该图像与启动图像显示的图像相同

我正确设置了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或IOS7,视网膜与否,以及哪个方向。如果每次显示图像时仍需要检查设备、方向、是否为视网膜,那么资产目录的意义何在?我认为这是他们的原因之一

我应该注意到,这是工作,因为我期待在我的应用程序在过去的工作。然后,我更改了资产目录中的图像,所有这些图像仍在工作。然而,我决定改变图像回到原来的,这是一切都打破了。我尝试过清理构建,甚至删除派生数据并重新启动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-grait~ipad.png的文件。我现在使用以下命令加载图像

    [self.backgroundImageView setImage:[UIImage imageNamed:@"background"]];
我试过background和background.png。但是,不显示图像,且image.size为0,0。UIImage ImageName给了我一个零的图像


我现在完全不知所措。

这是LaunchImage的完整列表:

  • 发射图像-568h@2x.png
  • 发射图像-700-568h@2x.png
  • 发射图像-700-Landscape@2x.png
  • 启动image-700-scanner.png
  • 发射图像-700-Portrait@2x.png
  • 启动image-700-grait.png
  • 发射图像-700@2x.png
  • 发射图像-Landscape@2x.png
  • LaunchImage-scape.png
  • 发射图像-Portrait@2x.png
  • 启动image-grait.png
  • LaunchImage.png
  • LaunchImage@2x.png
所以,你可能需要先检查方向,然后得到正确的图像。请考虑使用类似

的东西。
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (UIInterfaceOrientationIsPortrait(orientation)) {
    imageName = @"LaunchImage-Portrait";
} else {
    imageName = @"LaunchImage-Landscape";
}

我们假设您的资产目录中已正确设置了所有发布映像。当我之前用不同的图像设置它时,它就工作了。我改变了那个图像,它仍然有效,现在我又改变了它,它不起作用了。我还查看了资产目录,没有一个图像的名称与您描述的相同。资产目录会创建这些,事实上我看到了json文件设置的所有图像。我将补充这一点,作为对我原来问题的更新。要查看生成后图像的命名方式,您必须执行几个简单的步骤。1) 产品-存档-分发-为企业或临时部署保存-导出2)将result.ipa重命名为.zip并取消存档。3) 转到payload-app name-ctr单击它->在那里显示软件包内容,你会看到带有我描述的后缀的LaunchImages。@AlexanderKostiev为什么是700?还有x3图像和iPad呢?