iOS 7 / Xcode 5:以编程方式访问设备启动图像 [英] iOS 7 / Xcode 5: Access device launch images programmatically

查看:81
本文介绍了iOS 7 / Xcode 5:以编程方式访问设备启动图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法将应用程序LaunchImage用作通用iOS应用程序中的背景而不在多个位置放置相同的图像资源?

Is there any way to use the apps LaunchImage as a background in an universal iOS app without putting the same image resources in multiple places?

我无法使用访问 Images.xcassets 中的 LaunchImage 文件,因此我创建了两个新的图像集Background Portrait和Background横向(因为似乎无法将横向和纵向图像放入同一组中)。

I wasn't able to access the LaunchImage files in Images.xcassets, so I created two new Image Sets "Background Portrait" and "Background Landscape" (since there seems to be no way to put landscape and portrait images into the same set).

虽然这种解决方法完成了这些工作,但我不愿意包括每一个图像进入应用程序两次。这也有很高的维护成本。

While this workaround does the jobs, I would hate to include every image into the app twice. This also has a high maintenance cost.

有关如何访问当前设备的LaunchImage的任何建议都表示赞赏。

Any advice on how to access the LaunchImage for the current device is appreciated.

GCOLaunchImageTransition 必须完成iOS<的工作。 7。

GCOLaunchImageTransition must have done the job for iOS < 7.

推荐答案

您可以使用启动图像而无需包含它们两次。关键是当您使用资产目录时,应用程序包中包含的图像的文件名是(有点)标准化的,可能与您为原始文件命名的内容无关。

You can use the launch images without having to include them twice. The key is that when you use an asset catalog, the file names of the images that are included in the app bundle are (sort of) standardized and may not be related to what you've named the original files.

特别是,当您使用LaunchImage图像集时,应用程序包中的文件名称为

In particular, when you use the LaunchImage image set, the files that end up in the application bundle have names like


  • LaunchImage.png

  • LaunchImage@2x.png

  • LaunchImage-700@2x.png

  • LaunchImage-568h@2x.png

  • LaunchImage-700-568h@2x.png

  • LaunchImage-700-Landscape @ 2x~ipad .png

  • LaunchImage.png
  • LaunchImage@2x.png
  • LaunchImage-700@2x.png
  • LaunchImage-568h@2x.png
  • LaunchImage-700-568h@2x.png
  • LaunchImage-700-Landscape@2x~ipad.png

等。请注意,特别是它们未命名为 Default.png 或其任何变体。即使那就是你所谓的文件。一旦你把它们放在资产目录中的一个中,它们就会以标准名称出现在另一端。

etc. Note, in particular, they are not named Default.png or any variation of that. Even if that's what you called the files. Once you've dropped them in one of the wells in the asset catalog, they come out the other end with a standard name.

所以 [UIImage imageNamed:@Default] 将无效,因为应用包中没有此类文件。但是, [UIImage imageNamed:@LaunchImage] 将起作用(假设您已经填充了iPhone Portrait 2x或者 pre iOS7 iPhone肖像1x井)。

So [UIImage imageNamed:@"Default"] won't work because there is no such file in the app bundle. However, [UIImage imageNamed:@"LaunchImage"] will work (assuming you've filled either the iPhone Portrait 2x well or the pre iOS7 iPhone Portrait 1x well).

文档表明 UIImage <上 imageNamed:方法/ code>应该自动选择正确的版本,但我认为这仅适用于启动图像以外的图像集 - 至少我没有让它正常工作(可能只是我没有做正确的事情)。

The documentation indicates that the imageNamed: method on UIImage should auto-magically select the correct version, but I think this only applies to image sets other than the launch image--at least I've not gotten it to work quite correctly (could just be me not doing something right).

因此,根据您的具体情况,您可能需要进行一些试验和错误才能获得正确的文件名。在模拟器中构建并运行应用程序,然后您可以随时查看〜/ Library / Application Support / iPhone Simulator 的相应子目录,以验证实际文件名在应用程序包是。

So depending on your exact circumstances, you might need to do a little trial and error to get the correct file name. Build and run the app in the simulator and then you can always look in the appropriate subdirectory of ~/Library/Application Support/iPhone Simulator to verify what the actual file names in the app bundle are.

但同样重要的是,没有必要包含图像文件的副本,您不需要对图像文件进行任何调整。 复制捆绑资源构建阶段。

But again, the main point is that there is no need to include duplicates of the image files and you don't need to make any adjustments to the Copy Bundle Resources build phase.

这篇关于iOS 7 / Xcode 5:以编程方式访问设备启动图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆