xcode 将正确的全屏图像设置为我的启动屏幕 xib

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25801708/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 05:32:13  来源:igfitidea点击:

Setting the correct full-screen image as my launch screen xib

iosxcode

提问by Dan Fabulich

We want to support iOS 6 through iOS 8. By my count, that means we need to create ten launch images.

我们希望支持 iOS 6 到 iOS 8。据我所知,这意味着我们需要创建十张启动图像。

  • portrait 2x3: 320x480 640x480
  • portrait 9x16: 640x1136 750x1334 1242x2208
  • portrait 3x4: 768x1024 1536x2048
  • landscape 16x9: 2208x1242
  • landscape 4x3: 1024x768 2048x1536
  • 纵向 2x3:320x480 640x480
  • 纵向 9x16:640x1136 750x1334 1242x2208
  • 纵向 3x4:768x1024 1536x2048
  • 横向 16x9:2208x1242
  • 横向 4x3:1024x768 2048x1536

What I wish is that I could just generate the largest sized image at each ratio, and that iOS would just downsample the image for the other sizes. That would save me from adding five more launch images to my app, a nice savings in download size.

我希望我可以在每个比例下生成最大尺寸的图像,而 iOS 只会对其他尺寸的图像进行下采样。这将使我不必再向我的应用程序添加五个启动图像,从而大大节省了下载大小。

Is it possible to use the new feature of Xcode 6 to replace my launch images with storyboards(aka UILaunchStoryboardName) to do what I want?

是否可以使用 Xcode 6 的新功能用故事板(又名 UILaunchStoryboardName)替换我的启动图像来做我想做的事?

It seems pretty close, but I can't figure out how to say, "At 2x3, use image X; at 9x16, use image Y; at 3x4, use image Z" and so on. Size classes don't seem to let me express that concept cleanly. (Or do they?)

看起来很接近,但我不知道如何说,“在 2x3,使用图像 X;在 9x16,使用图像 Y;在 3x4,使用图像 Z”等等。尺寸等级似乎并没有让我清楚地表达这个概念。(或者他们是?)

回答by jmdecombe

Here is one way to do this... Create a new image set in your existing or some new assets catalog. By default, the Devices field of the new image set, in the right pane, will be set to Universal, and so you should see three image wells in the main view: 1x, 2x, and 3x. What you want is to set the Devices field to Device Specific, then check iPhone, Retina 4-inch, and iPad underneath that field. Then, you will now see six images wells. There are four for iPhone: 1x, 2x, Retina 4 2x, and 3x. There are two for iPad: 1x, and 2x. Now, all you have to do is to drag your versions of the same splash image in various device-specific sizes, into the appropriate image wells. Once you are done, go to your launch screen XIB, which by default is set to Any width and Any height, and add a UIImageView, setting the image to have the same name as the image set you just created. Adjust the image to have the same size as the enclosing view, adding top, leading, bottom, and trailing constraints with a constant value of 0, so that the image size adjusts with the view size, regardless of the device. Run the app on your device and you should see the correct splash upon launch. You can set a breakpoint at the top of your AppDelegate code, e.g. right underneath the var window: UIWindow? declaration (or equivalent if using Objective C), so you can verify the splash on different kinds of device. Note that the image may not work in the Simulator, so try on a device. I guess that it is a bug in the Simulator, or unimplemented feature.

这是执行此操作的一种方法... 在您现有的或一些新的资产目录中创建一个新图像集。默认情况下,右侧窗格中新图像集的设备字段将设置为通用,因此您应该在主视图中看到三个图像井:1x、2x 和 3x。您想要的是将 Devices 字段设置为 Device Specific,然后检查该字段下方的 iPhone、Retina 4 英寸和 iPad。然后,您现在将看到六个图像井。iPhone 有四种:1x、2x、Retina 4 2x 和 3x。iPad 有两种:1x 和 2x。现在,您所要做的就是将不同设备特定尺寸的相同初始图像的版本拖到适当的图像井中。完成后,转到启动屏幕 XIB,默认设置为任意宽度和任意高度,然后添加一个 UIImageView,将图像设置为与您刚刚创建的图像集具有相同的名称。将图像调整为与封闭视图相同的大小,添加顶部、前导、底部和尾部约束,常量值为 0,以便图像大小随视图大小调整,而不管设备如何。在您的设备上运行该应用程序,您应该会在启动时看到正确的启动画面。您可以在 AppDelegate 代码的顶部设置断点,例如在 var 窗口的正下方:UIWindow?声明(或等效的,如果使用目标 C),因此您可以验证不同类型设备上的飞溅。请注意,该图像可能无法在模拟器中运行,因此请在设备上尝试。我猜这是模拟器中的一个错误,或者是未实现的功能。和尾随约束的常量值为 0,以便图像大小随视图大小调整,而不管设备如何。在您的设备上运行该应用程序,您应该会在启动时看到正确的启动画面。您可以在 AppDelegate 代码的顶部设置断点,例如在 var 窗口的正下方:UIWindow?声明(或等效的,如果使用目标 C),因此您可以验证不同类型设备上的飞溅。请注意,该图像可能无法在模拟器中运行,因此请在设备上尝试。我猜这是模拟器中的一个错误,或者是未实现的功能。和尾随约束的常量值为 0,以便图像大小随视图大小调整,而不管设备如何。在您的设备上运行该应用程序,您应该会在启动时看到正确的启动画面。您可以在 AppDelegate 代码的顶部设置断点,例如在 var 窗口的正下方:UIWindow?声明(或等效的,如果使用目标 C),因此您可以验证不同类型设备上的飞溅。请注意,该图像可能无法在模拟器中运行,因此请在设备上尝试。我猜这是模拟器中的一个错误,或者是未实现的功能。界面窗口?声明(或等效的,如果使用目标 C),因此您可以验证不同类型设备上的飞溅。请注意,该图像可能无法在模拟器中运行,因此请在设备上尝试。我猜这是模拟器中的一个错误,或者是未实现的功能。界面窗口?声明(或等效的,如果使用目标 C),因此您可以验证不同类型设备上的飞溅。请注意,该图像可能无法在模拟器中运行,因此请在设备上尝试。我猜这是模拟器中的一个错误,或者是未实现的功能。

One thing I am not sure about is where to specify the image for iPhone 6. It seems that there are device specific image wells only for iPhone pre-4s, iPhone 4s, iPhone 5, iPhone 6 Plus, iPad, and iPad Retina sizes.

我不确定的一件事是在哪里指定 iPhone 6 的图像。似乎只有 iPhone pre-4s、iPhone 4s、iPhone 5、iPhone 6 Plus、iPad 和 iPad Retina 尺寸才有特定于设备的图像井。