简体   繁体   English

如何在启动故事板中使用资产目录中的启动映像?

[英]How do I use the Launch Images from an Asset Catalogue in the Launch Storyboard?

I do need to support both storyboard-based launch screens and 'traditional' launch images in a project. 我确实需要支持基于故事板的启动屏幕和项目中的“传统”启动图像。

Adding a Launch Screen storyboard with an UIImageView pointing to the launch screen seemed like a straightforward way of doing so. 使用指向启动屏幕的UIImageView添加启动屏幕故事板似乎是一种直接的方式。 Yet, Interface Builder cannot locate the launch image and cannot display it at all. 但是,Interface Builder无法找到启动映像,也无法显示它。

As all sizes differ also in content, will the storyboard even select the right image? 由于所有尺寸的内容也不同,故事板是否会选择正确的图像?

Reconstructing the images with size classes and constraints is not quite possible, so 用尺寸类和约束重建图像是不可能的,所以

TL;DR : How do use a Launch Storyboard that uses the corresponding images from the set of launch screen images? TL; DR :如何使用启动故事板使用发布屏幕图像集中的相应图像?

In Assets.xcassets, click on + and select App Icons & Launch Images --> New iOS Launch Image. 在Assets.xcassets中,单击+并选择App Icons&Launch Images - > New iOS Launch Image。 Drag & Drop your Launch Images with the mentioned sizes. 使用上述尺寸拖放启动图像。 Now in Project & targets List, select your Project & then General Tab. 现在在项目和目标列表中,选择您的项目然后选择常规选项卡。 In App Icons & Launch Images, click on Launch Images Source & select your newly created source file. 在应用程序图标和启动图像中,单击启动图像源并选择新创建的源文件。

I know this is an old question. 我知道这是一个老问题。 Short answer is "you can't", but there is a workaround. 简短的回答是“你不能”,但有一个解决方法。

Here is how I do it: 我是这样做的:

Do not add the images you want to use to an asset catalog. 请勿将要使用的图像添加到资产目录中。 Instead, add the images directly to your project and make sure you have them included in the target. 而是将图像直接添加到项目中,并确保将它们包含在目标中。 You have to go back to the old "image.png", "image@2.png", "image@3.png" naming convention in order to supply different images for different screen sizes. 您必须返回旧的“image.png”,“image@2.png”,“image@3.png”命名约定,以便为不同的屏幕尺寸提供不同的图像。

Hope that helps anyone who comes across this. 希望能帮助遇到这个问题的人。

将图像添加到目标 在LaunchScreen故事板中将图像设置为ImageView $$$

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM