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

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

问题描述

有没有什么办法可以在通用的iOS应用中使用LaunchImage作为背景,而不需要在多个地方放置相同的图片资源?

我无法访问 Images.xcassets 中的 LaunchImage 文件,所以我创建了两个新的图像集Background Portrait"和Background Landscape"(因为好像没有办法把横向和纵向图像放在同一个集合中).

虽然这种解决方法可以完成工作,但我不想将每个图像都包含在应用程序中两次.这也有很高的维护成本.

感谢有关如何访问当前设备的 LaunchImage 的任何建议.

GCOLaunchImageTransition 必须为 iOS 完成这项工作7.

解决方案

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

特别是,当您使用 LaunchImage 图像集时,最终出现在应用程序包中的文件的名称类似于

  • Lau​​nchImage.png
  • Lau​​nchImage@2x.png
  • Lau​​nchImage-700@2x.png
  • Lau​​nchImage-568h@2x.png
  • Lau​​nchImage-700-568h@2x.png
  • Lau​​nchImage-700-Landscape@2x~ipad.png

等等.请特别注意,它们没有被命名为 Default.png 或它的任何变体.即使这就是你所说的文件.一旦您将它们放入资产目录中的一个,它们就会以标准名称从另一端出来.

所以 [UIImage imageNamed:@"Default"] 将不起作用,因为应用程序包中没有这样的文件.但是,[UIImage imageNamed:@"LaunchImage"] 会起作用(假设您已经填充了 iPhone Portrait 2x 或 iOS7 之前 iPhone Portrait 1x 很好).

文档表明 UIImage 上的 imageNamed: 方法应该自动神奇地选择正确的版本,但我认为这仅适用于启动图像以外的图像集-- 至少我还没有让它正常工作(可能只是我做错了什么).

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

但同样,重点是不需要包含图像文件的重复项,并且您不需要对Copy Bundle Resources 构建阶段进行任何调整.

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?

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.

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

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.

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

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.

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).

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).

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天全站免登陆