xcode 如何使用 UILaunchImages 键
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26441782/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to use UILaunchImages Key
提问by master45
I edited the info.plist and added the UILaunchImages Key. However, I can't get the app to display the launch image that I want. I am doing this to try and create a landscape launch image for iphones. Here's the code.
我编辑了 info.plist 并添加了 UILaunchImages 键。但是,我无法让应用程序显示我想要的启动图像。我这样做是为了尝试为 iphone 创建横向启动图像。这是代码。
<key>UILaunchImages</key>
<array>
<dict>
<key>UILaunchImageMinimumOSVersion</key>
<string>8.0</string>
<key>UILaunchImageName</key>
<string>Default</string>
<key>UILaunchImageOrientation</key>
<string>Portrait</string>
<key>UILaunchImageSize</key>
<string>{320, 480}</string>
</dict>
<dict>
<key>UILaunchImageMinimumOSVersion</key>
<string>8.0</string>
<key>UILaunchImageName</key>
<string>Default</string>
<key>UILaunchImageOrientation</key>
<string>Landscape</string>
<key>UILaunchImageSize</key>
<string>{320, 480}</string>
</dict>
<dict>
<key>UILaunchImageMinimumOSVersion</key>
<string>8.0</string>
<key>UILaunchImageName</key>
<string>Default-568h</string>
<key>UILaunchImageOrientation</key>
<string>Portrait</string>
<key>UILaunchImageSize</key>
<string>{320, 568}</string>
</dict>
<dict>
<key>UILaunchImageMinimumOSVersion</key>
<string>8.0</string>
<key>UILaunchImageName</key>
<string>Default-568h</string>
<key>UILaunchImageOrientation</key>
<string>Landscape</string>
<key>UILaunchImageSize</key>
<string>{320, 568}</string>
</dict>
<dict>
<key>UILaunchImageMinimumOSVersion</key>
<string>8.0</string>
<key>UILaunchImageName</key>
<string>Default-667h</string>
<key>UILaunchImageOrientation</key>
<string>Portrait</string>
<key>UILaunchImageSize</key>
<string>{375, 667}</string>
</dict>
<dict>
<key>UILaunchImageMinimumOSVersion</key>
<string>8.0</string>
<key>UILaunchImageName</key>
<string>Default-667h</string>
<key>UILaunchImageOrientation</key>
<string>Landscape</string>
<key>UILaunchImageSize</key>
<string>{375, 667}</string>
</dict>
<dict>
<key>UILaunchImageMinimumOSVersion</key>
<string>8.0</string>
<key>UILaunchImageName</key>
<string>Default-736h</string>
<key>UILaunchImageOrientation</key>
<string>Portrait</string>
<key>UILaunchImageSize</key>
<string>{414, 736}</string>
</dict>
<dict>
<key>UILaunchImageMinimumOSVersion</key>
<string>8.0</string>
<key>UILaunchImageName</key>
<string>Default-736h</string>
<key>UILaunchImageOrientation</key>
<string>Landscape</string>
<key>UILaunchImageSize</key>
<string>{414, 736}</string>
</dict>
<dict>
<key>UILaunchImageMinimumOSVersion</key>
<string>8.0</string>
<key>UILaunchImageName</key>
<string>Default-Portrait</string>
<key>UILaunchImageOrientation</key>
<string>Portrait</string>
<key>UILaunchImageSize</key>
<string>{768, 1024}</string>
</dict>
<dict>
<key>UILaunchImageMinimumOSVersion</key>
<string>8.0</string>
<key>UILaunchImageName</key>
<string>Default-Landscape</string>
<key>UILaunchImageOrientation</key>
<string>Landscape</string>
<key>UILaunchImageSize</key>
<string>{768, 1024}</string>
</dict>
</array>
I want to replace default with an image of my own, but when I do that it just shows a black screen. Am I missing a step? Is this an iOS 8 problem?
我想用我自己的图像替换默认值,但是当我这样做时,它只显示黑屏。我错过了一步吗?这是 iOS 8 的问题吗?
回答by W S
Apple technical note TN2244 (https://developer.apple.com/library/ios/technotes/tn2244/_index.html) provides some basic information on how to add UILaunchImages for iPhone apps that launch only into landscape mode, especially if you want to support iOS8 and iOS7. (Specifically, it gives the XML code shown above, which, once pasted into the Info.plist file, can then be edited in XCode's Project Settings - Info tab). The associated images should be dragged into Xcode's Project Explorer.
Apple 技术说明 TN2244 ( https://developer.apple.com/library/ios/technotes/tn2244/_index.html) 提供了有关如何为仅以横向模式启动的 iPhone 应用程序添加 UILaunchImages 的一些基本信息,特别是如果您需要支持iOS8和iOS7。(具体来说,它给出了上面显示的 XML 代码,一旦粘贴到 Info.plist 文件中,就可以在 XCode 的项目设置 - 信息选项卡中进行编辑)。关联的图像应该被拖到 Xcode 的 Project Explorer 中。
That Technical Note also says that in order to support both iOS8 and prior versions, the Asset Catalog must not be used.
该技术说明还指出,为了支持 iOS8 和之前的版本,不得使用资产目录。
So it is a good starting point, but for me it needed further fleshing out. For my app, which I want to be able to run starting from iPhone4s/iOS7 up to iPhone6Plus/iOS8.x in landscape-only, I ran into various problems. The biggest was that although I had created the various launch images (in landscape mode, then rotated them to portrait), added them to my project, and placed the names into the UILaunchImages dictionary exactly as in the Technical Note, the launch image would show correctly for iPhone4s/iOS7, but on iPhone5* and iPhone6, inspite of what was in the LaunchImages, would pick up the iPhone4 image, which it would further rotate before displaying it.
所以这是一个很好的起点,但对我来说它需要进一步充实。对于我的应用程序,我希望能够在仅横向模式下从 iPhone4s/iOS7 运行到 iPhone6Plus/iOS8.x,我遇到了各种问题。最大的是,尽管我已经创建了各种启动图像(在横向模式下,然后将它们旋转为纵向),将它们添加到我的项目中,并将名称完全按照技术说明中的名称放入 UILaunchImages 字典中,但启动图像将显示对 iPhone4s/iOS7 来说是正确的,但在 iPhone5* 和 iPhone6 上,不管 LaunchImages 中有什么,都会拾取 iPhone4 图像,它会在显示之前进一步旋转。
Worse, iPhone5 and iPhone6 would then run only in letterboxed mode, and report screen sizes of 320x480 points. Running on anything under iOS8, I would get the default screen from the LaunchScreen.xib file. I did not want that, either, because I cannot use autolayout at the moment.
更糟糕的是,iPhone5 和 iPhone6 将仅在信箱模式下运行,并报告 320x480 点的屏幕尺寸。在 iOS8 下的任何东西上运行,我都会从 LaunchScreen.xib 文件中获得默认屏幕。我也不想要那个,因为我现在不能使用自动布局。
The solution I found was posted by Alex Argo, see the question (How do I create launch images for iPhone 6 / 6 Plus Landscape Only Apps?). This involves adding further keys to the Info.plist, also for portrait images even though they are not used. Note below the additional entries for Portrait, which are not included in the Technical Note.
我找到的解决方案由 Alex Argo 发布,请参阅问题(如何为 iPhone 6 / 6 Plus Landscape Only Apps 创建启动图像?)。这涉及向 Info.plist 添加更多键,即使它们没有被使用,也适用于肖像图像。请注意下方的纵向附加条目,这些条目未包含在技术说明中。
<key>UILaunchImages</key>
<array>
<dict>
<key>UILaunchImageMinimumOSVersion</key>
<string>7.0</string>
<key>UILaunchImageName</key>
<string>Img320x568ptsPort@2x</string>
<key>UILaunchImageOrientation</key>
<string>Landscape</string>
<key>UILaunchImageSize</key>
<string>{320, 568}</string>
</dict>
<dict>
<key>UILaunchImageMinimumOSVersion</key>
<string>7.0</string>
<key>UILaunchImageName</key>
<string>Img320x568ptsLdsc@2x</string>
<key>UILaunchImageOrientation</key>
<string>Portrait</string>
<key>UILaunchImageSize</key>
<string>{320, 568}</string>
</dict>
<dict>
<key>UILaunchImageMinimumOSVersion</key>
<string>7.0</string>
<key>UILaunchImageName</key>
<string>Img320x480ptsPort@2x</string>
<key>UILaunchImageOrientation</key>
<string>Landscape</string>
<key>UILaunchImageSize</key>
<string>{320, 480}</string>
</dict>
<dict>
<key>UILaunchImageMinimumOSVersion</key>
<string>7.0</string>
<key>UILaunchImageName</key>
<string>Img320x480ptsLdsc@2x</string>
<key>UILaunchImageOrientation</key>
<string>Portrait</string>
<key>UILaunchImageSize</key>
<string>{320, 480}</string>
</dict>
<dict>
<key>UILaunchImageMinimumOSVersion</key>
<string>8.0</string>
<key>UILaunchImageName</key>
<string>Img375x667ptsPort@2x</string>
<key>UILaunchImageOrientation</key>
<string>Landscape</string>
<key>UILaunchImageSize</key>
<string>{375, 667}</string>
</dict>
<dict>
<key>UILaunchImageMinimumOSVersion</key>
<string>8.0</string>
<key>UILaunchImageName</key>
<string>Img375x667ptsLdsc@2x</string>
<key>UILaunchImageOrientation</key>
<string>Portrait</string>
<key>UILaunchImageSize</key>
<string>{375, 667}</string>
</dict>
<dict>
<key>UILaunchImageMinimumOSVersion</key>
<string>8.0</string>
<key>UILaunchImageName</key>
<string>Img414x736ptsLdsc@3x</string>
<key>UILaunchImageOrientation</key>
<string>Landscape</string>
<key>UILaunchImageSize</key>
<string>{414, 736}</string>
</dict>
<dict>
<key>UILaunchImageMinimumOSVersion</key>
<string>8.0</string>
<key>UILaunchImageName</key>
<string>Img414x736ptsPort@3x</string>
<key>UILaunchImageOrientation</key>
<string>Portrait</string>
<key>UILaunchImageSize</key>
<string>{414, 736}</string>
</dict>
</array>
Interestingly, for iPhone 6Plus, I found that there is no need to rotate a landscape launch image to portrait, as was necessary for all the other landscape launch images.
有趣的是,对于 iPhone 6Plus,我发现不需要像所有其他横向启动图像那样将横向启动图像旋转为纵向。
It also involved blanking out, in the Project Settings, the "Lauch Screen File". Otherwise the default LaunchScreen.xib would sometimes get picked up as the launch screen cases (which is no good to me because the interplay between graphics and text in my app kinda precludes autolayout at this point).
它还涉及在项目设置中消隐“启动屏幕文件”。否则默认的 LaunchScreen.xib 有时会被选为启动屏幕案例(这对我来说没有好处,因为我的应用程序中图形和文本之间的相互作用在这一点上排除了自动布局)。
All of this works for me under Xcode 6.4.
所有这些都适用于 Xcode 6.4 下的我。