且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

支持 iOS6 和 iOS7 的启动画面 - 强制启动画面

更新时间:2023-01-25 23:30:46

简短回答

在 iOS 7 中,应用可以根据运行的 iOS 版本使用不同的启动图像.要提供不同的启动图像,请将 UILaunchImages 键添加到 Info.plist 文件并使用描述每个启动图像的字典.

Short answer

In iOS 7, an app can use a different launch image depending on which version of iOS it’s running in. To provide different launch images, add the UILaunchImages key to the Info.plist file and use a dictionary to describe each launch image.

它使用以下键:

UILaunchImageName - 包含 PNG 图像文件名称的字符串.图像文件必须位于应用程序包的顶层.您为此键指定的名称不应包含文件名扩展名,也不应该包含修饰符,例如@2x、-568h、~iphone 或 ~ipad.

UILaunchImageName - A string containing the name of the PNG image file. The image file must reside at the top level of the app bundle. The name you specify for this key should not include a filename extension, nor should it include modifiers such as @2x, -568h, ~iphone, or ~ipad.

在磁盘上,您的图像文件名可能仍包含@2x、-568h、~iphone 或 ~ipad 修饰符视情况而定,尽管它们不是必需的.系统会在以下情况下自动考虑此类修饰符选择要加载的文件.

On disk, your image filenames may still include the @2x, -568h, ~iphone, or ~ipad modifiers as appropriate, although they are not required. The system automatically accounts for such modifiers when choosing which file to load.

UILaunchImageMinimumOSVersion - 对于 iOS7,这应该是一个字符串7.0".

UILaunchImageMinimumOSVersion - for iOS7 this should be a string "7.0".

UILaunchImageOrientation – 包含以下一项的字符串:Portrait、PortraitUpsideDown、Landscape、LandscapeLeft、LandscapeRight.

UILaunchImageOrientation – String containing one of: Portrait, PortraitUpsideDown, Landscape, LandscapeLeft, LandscapeRight.

UILaunchImageSizeString 指定宽度和高度,例如:{320, 480}".您必须指定宽度和高度设备处于纵向.换句话说,肖像和针对同一设备的横向图像将具有相同的宽度和身高.

UILaunchImageSizeString specifying width and height, ex: "{320, 480}". You must specify the width and height with respect to the device in a portrait orientation. In other words, portrait and landscape images targeting the same device would have the same width and height.

如果这个键存在,iOS 7 只使用它来获取启动图片.

If this key is present, iOS 7 uses it exclusively to obtain launch images.

但是:我发现坚持 iOS7 的命名约定也有很大帮助!

BUT: I found that sticking to the naming convention also for iOS7 helped a lot!

iOS 7.0 及更高版本支持此密钥.

This key is supported in iOS 7.0 and later.

好的——那现在怎么办?

因为我已经有了适用于 iOS6 的启动图像及其所有特定的命名约定.我选择制作所有这些的副本,并在名称前加上iOS7-",以限制我自己对所有不同大小和名称的混淆.制作前缀应该会派上用场,因为大多数图像会立即被正确加载.

OK – so now what?

Because I already had launch images for iOS6 and with all their specific naming conventions. I chose to make a copy of all of them and prefix the name with "iOS7-" so as to limit my own confusion about all the different sizes and names. Making a prefix should prove to come in handy as then most of the images would immediately be loaded correctly.

文件名:我已经为 iOS6 准备了这些,我还列出了需要的文件大小:

The filenames: I had these for iOS6 already, I also list the file sizes for those in need:

  • Default.png (320x480)
  • 默认@2x.png (640x960)
  • 默认@2x~ipad.png (2048x1496)
  • 默认~ipad.png (768x1004)
  • Default1024x768.png (1024x768)
  • Default1024x768@2x.png (2048x1536)
  • Default-568h@2x.png (640x1136)
  • Default768x1024.png (768x1024)
  • Default768x1024@2x.png (1536x2048)
  • 默认-横向~ipad.png (1024x748)
  • 默认-Portrait@2x~ipad.png (1536x2048)

因此,我为 iOS7(相同大小)复制了所有这些文件名,并在它们前面加上了iOS7-":

So I made a copy of all of these filenames for iOS7 (same sizes) prefixing them with "iOS7-":

  • iOS7-Default.png
  • iOS7-Default@2x.png
  • ...

现在在 PLIST 中创建您的条目.转到您的应用程序名称.plist.在空白区域,右键单击并选择添加行".确保它成为 .plist 中某些其他信息的顶部项目而不是子项目.

Now to create your entry in PLIST. Go to your-name-of-application.plist. In a blank area, right-click and choose "Add Row". Make sure it becomes a top item and not a sub-item of some other information in the .plist.

写:UILaunchImages

右键单击此 UILaunchImages 并选择值类型Array".

Right-click on this UILaunchImages and select value type "Array".

使用下面的插图作为文本的指南以及完成后的外观:

Use the illustration below as a guide to the text and for how it will look when it is all finished:

如果你打开这个数组,让左边的小指示三角形指向下,第一次它是空的,但如果你在打开时选择添加行",它将创建一个子线.现在就这样做:

If you open up this array so the little indicator triangle to the left points down, it is empty the first time, but if you choose "add row" while it is open it will create a sub-line. Do that now:

右键单击 UILaunchImages 并选择添加行".右键单击这个新行(项目 0)并选择值类型Dict"

Right-click on the UILaunchImages and select "Add row". Right-click on this new line (item 0) and select value type "Dict"

继续使用三角形指示器打开此项目并右键单击并添加行"

Continue opening this items with the triangle indicator and right-click and "Add row"

您将此项命名为 UILaunchImageMinimumOSVersion 并将值类型设置为string",将字符串设置为7.0"

This item you will name UILaunchImageMinimumOSVersion and set value type to "string" and the string to "7.0"

现在以下都是字符串,应该与 UILaunchImageMinimumOSVersion 项处于同一级别.在同一个字典(字典)中.只需为每个选择添加行"即可创建这些:

Now the following are all strings and should be at the same level as the UILaunchImageMinimumOSVersion item. In the same dict (dictionary). Create these by just choosing "Add row" for each:

UILaunchImageName – iOS7-launch-image 的基本名称.就我而言,这是iOS7-默认"

UILaunchImageName – base-name-of-iOS7-launch-image. In my case this was "iOS7-Default"

UILaunchImageOrientation - 示例:纵向

UILaunchImageSize - 基本 iOS7-Default.png 的大小:{320, 480}".该程序将找到所有具有基本名称排列的文件.请记住选择没有 ipad/iphone/portrait/landscape 或 .png 规范的文件的基本名称.

UILaunchImageSize - the size of the elementary base iOS7-Default.png: "{320, 480}". The program will find all the files with permutations of the base name. Remember to select the base name of the file without ipad/iphone/portrait/landscape or .png specifications.

注意:

在所有可用插槽中首次添加 iOS6 图像后,Xcode 已经在 .plist 中为我制作了以下项目:-)

Xcode had already made the following items in the .plist for me after first adding iOS6 images in all available slots :-)

UILaunchImageFile~ipad ... = "Default"——所以没问题

UILaunchImageFile~ipad … = "Default" – so this was OK

UILaunchImages~ipad ... 有两个项目需要更新到 iOS7 版本,因为它们现在错误地保存了 iOS6 版本.那些我已经命名为 Default1024x768 和 Default768x1024 的,现在我只是在每个名称前加上iOS7-",我就完成了.

UILaunchImages~ipad … Had two items that needed to be updated to iOS7 versions, because they where now incorrectly holding the iOS6 version. Those I had named Default1024x768 and Default768x1024 and now I just prefixed "iOS7-" to each of the names and I was done.

<key>UILaunchImages</key>
  <array>
    <dict>
      <key>UILaunchImageMinimumOSVersion</key>
      <string>7.0</string>
      <key>UILaunchImageName</key>
      <string>iOS7-Default </string>
      <key>UILaunchImageOrientation</key>
      <string>Portrait</string>
      <key>UILaunchImageSize</key>
      <string>{320, 480}</string>
    </dict>
  </array>

[jd 修正了UILaunchImages"的拼写]

[edit by jd: fixed spelling of "UILaunchImages"]