如何使用UILaunchImages Key

时间:2014-10-18 16:07:57

标签: ios arrays xcode

我编辑了info.plist并添加了UILaunchImages Key。但是,我无法让应用程序显示我想要的启动图像。我这样做是为了尝试为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>

我想用我自己的图像替换默认值,但是当我这样做时它只显示黑屏。我错过了一步吗?这是iOS 8问题吗?

1 个答案:

答案 0 :(得分:2)

Apple技术说明TN2244(https://developer.apple.com/library/ios/technotes/tn2244/_index.html)提供了有关如何为仅启用横向模式的iPhone应用程序添加UILaunchImages的一些基本信息,尤其是在您想要支持iOS8和iOS7时。 (具体来说,它提供了上面显示的XML代码,一旦粘贴到Info.plist文件中,就可以在XCode的项目设置 - 信息选项卡中进行编辑)。应将相关图像拖入Xcode的Project Explorer。

该技术说明还说,为了支持iOS8和以前的版本,不得使用资产目录。

所以这是一个很好的起点,但对我来说还需要进一步充实。 对于我的应用程序,我希望能够从iPhone4s / iOS7到iPhone6Plus / iOS8.x仅在横向上运行,我遇到了各种各样的问题。最大的问题是虽然我创建了各种启动图像(在横向模式下,然后将它们旋转为肖像),将它们添加到我的项目中,并将名称放入UILaunchImages字典中,与技术说明完全相同,启动图像将显示正确的iPhone4s / iOS7,但在iPhone5 *和iPhone6上,尽管在LaunchImages中,它会拿起iPhone4图像,它会在显示之前进一步旋转。

更糟糕的是,iPhone5和iPhone6将仅以信箱模式运行,并报告320x480点的屏幕尺寸。在iOS8下运行任何东西,我会从LaunchScreen.xib文件中获取默认屏幕。我也不想那样,因为我现在不能使用autolayout。

我发现的解决方案由Alex Argo发布,请参阅问题(How do I create launch images for 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>

有趣的是,对于iPhone 6Plus,我发现没有必要将风景启动图像旋转为肖像,这是所有其他风景启动图像所必需的。

它还涉及在项目设置中删除&#34; Lauch屏幕文件&#34;。否则默认的LaunchScreen.xib有时会被启动作为启动屏幕的情况(这对我不利,因为我的应用程序中的图形和文本之间的相互作用有时会排除自动布局)。

所有这些对我来说都适用于Xcode 6.4。