启动图像未显示在 iOS 应用程序中(使用 Images.xcassets)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27723547/
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
Launch Image not showing up in iOS application (using Images.xcassets)
提问by Sandy D.
I'm having some trouble getting my launch image to show up in my application.
我在让我的启动图像显示在我的应用程序中时遇到了一些麻烦。
I have created all the static image files in the Images.xcassets file in an asset set called "LaunchImage".
我已经在名为“LaunchImage”的资产集中的 Images.xcassets 文件中创建了所有静态图像文件。
I noticed that my project also contains a LaunchScreen.xib file (which was automatically created by Xcode).
我注意到我的项目还包含一个 LaunchScreen.xib 文件(由 Xcode 自动创建)。
This .xib file appears when I run the application on my iPhone6 device. It doesn't appear in the simulator for iPhone4s (which makes sense, since xib launch screen is only for iOS 8 +).
当我在 iPhone6 设备上运行应用程序时,会出现这个 .xib 文件。它没有出现在 iPhone4s 的模拟器中(这是有道理的,因为 xib 启动屏幕仅适用于 iOS 8 +)。
I want to use the static images that I have created since they fall under the Apple Guidelines and go with my application. However, I haven't had any luck at getting it to show up.
我想使用我创建的静态图像,因为它们属于 Apple 指南并与我的应用程序一起使用。但是,我没有运气让它出现。
I noticed under the project settings that there is a section called App Icons and Launch Images
. I see how the .xib is connected by the Launch Screen File option I assume.
我注意到在项目设置下有一个名为App Icons and Launch Images
. 我看到 .xib 是如何通过我假设的 Launch Screen File 选项连接的。
However, there is an option called Launch Image Sources
. What does this do?
但是,有一个选项称为Launch Image Sources
。这有什么作用?
I found this: http://matthewpalmer.net/blog/2014/09/10/iphone-6-plus-launch-image-adaptive-mode/. However, it didn't explain anything about the Launch Image Source option.
我发现了这个:http: //matthewpalmer.net/blog/2014/09/10/iphone-6-plus-launch-image-adaptive-mode/。但是,它没有解释有关“启动图像源”选项的任何信息。
There is a button next to the Launch Image Sources
called "Use Asset Catalog". When I click it, it just says Migrate Launch Images to an asset catalog. Your existing launch images will be copied into a new image set. Choose an asset catalog to use: .
在Launch Image Sources
名为“使用资产目录”的旁边有一个按钮。当我点击它时,它只是说将启动图像迁移到资产目录。您现有的启动图像将被复制到新的图像集中。选择要使用的资产目录:。
This is confusing to me because I've already created my asset catalog and I definitely don't want it to overwrite images.xcassets file. So, how do I link this to the Launch Images Asset Set that I already have created? Also what "existing launch images" is it referring to will be copied into a new image set?
这让我感到困惑,因为我已经创建了我的资产目录,我绝对不希望它覆盖 images.xcassets 文件。那么,如何将其链接到我已经创建的启动图像资产集?还有什么“现有的启动图像”是指将被复制到新的图像集中?
Thank you!
谢谢!
UPDATE 1
UPDATE 1
So, I tried the migrate images option and chose to the new set option. This caused a new image set to be created which I deleted. However, the name left in the Launch Image Source was set to LaunchImage which somehow connected to the image set that contains my launch images. It did mess up my LaunchImage set -- the images were set to unassigned. I deleted them and dragged my files to the appropriate box in the LaunchImage asset set. However, when I run the application it still doesn't work. =( Launch Image doesn't show up.
所以,我尝试了迁移图像选项并选择了新的设置选项。这导致创建了一个我删除的新图像集。但是,保留在 Launch Image Source 中的名称设置为 LaunchImage,它以某种方式连接到包含我的启动图像的图像集。它确实弄乱了我的 LaunchImage 集——图像被设置为未分配。我删除了它们并将我的文件拖到 LaunchImage 资产集中的相应框中。但是,当我运行该应用程序时,它仍然不起作用。=(启动图像不显示。
I even removed the information that was in Launch Screen File
(which my assumption was the setting that connects to the .xib file). Still, somehow the .xib file appears on my iPhone6 device. =(
我什至删除了其中的信息Launch Screen File
(我的假设是连接到 .xib 文件的设置)。尽管如此,.xib 文件还是以某种方式出现在我的 iPhone6 设备上。=(
Any ideas what's going on?
任何想法发生了什么?
回答by pierre
I had this problem. I tested on simulator. I left the "Launch screen file" blank and removed the line about the "launch screen file" inside the plist. I restarted Xcode. Nothing. In my case in was not black it was white. Xcode 7 target ios 9.
我有这个问题。我在模拟器上测试过。我将“启动屏幕文件”留空,并删除了 plist 中有关“启动屏幕文件”的行。我重新启动了Xcode。没有。就我而言,它不是黑色而是白色。Xcode 7 目标 ios 9。
i read this one as well: Launch Image does not show up in my iOS App
我也读过这个:启动图像没有显示在我的 iOS 应用程序中
The launch image only showed up when i deleted the app from the simulatorand run the app again.
仅当我从模拟器中删除应用程序并再次运行应用程序时,才会显示启动图像。
回答by Sandy D.
I finally figured it out!
我终于想通了!
So, in your project settings, go to the section that says: App Icons and Launch Images
因此,在您的项目设置中,转到以下部分: App Icons and Launch Images
Remove the information found in Launch Screen File
if you do not want to use .xib file.
Launch Screen File
如果您不想使用 .xib 文件,请删除中找到的信息。
Then, in Launch Image Source
, Choose to migrate and if you have already created your LaunchImage file and added the images to it. Then click the asset catalog that shows up. The name of the one that contains your Launch Images.
然后,在 中Launch Image Source
,选择迁移,如果您已经创建了 LaunchImage 文件并将图像添加到其中。然后单击显示的资产目录。包含您的启动图像的名称。
This will create a new Launch-Image2 in your image set. To use the one you already have created, click the drop-down menu next to Launch Image Source. And you should see your other Launch Image set. Choose it. Then re-build your application and run it. You should see your Launch Image. =)
这将在您的图像集中创建一个新的 Launch-Image2。要使用您已经创建的,请单击 Launch Image Source 旁边的下拉菜单。您应该会看到其他 Launch Image 集。选择它。然后重新构建您的应用程序并运行它。您应该会看到您的启动图像。=)
Hope this helps!
希望这可以帮助!
Note: it won't delete your images that you already have in the asset catalog. It will just create a new LaunchImage asset set.
注意:它不会删除您在资产目录中已有的图像。它只会创建一个新的 LaunchImage 资产集。
参考:https: //developer.apple.com/library/ios/recipes/xcode_help-image_catalog-1.0/chapters/StoringAppIconsandLaunchImagesinanAssetCatalog.html
回答by SwiftDeveloper
回答by iDevAmit
Working solution. Saved my timeand hope it will save yours as well.
工作解决方案。节省了我的时间,希望它也能节省你的时间。
- Make sure your images are accurate size according to Apple Guidelines.
- Make sure, You will select only one option , either launch screen file or Launch Image Source. You can find these two options in Project build settings -> General
- 根据Apple 指南,确保您的图像尺寸准确。
- 确保您将只选择一个选项,即启动屏幕文件或启动图像源。您可以在 Project build settings -> General 中找到这两个选项
Clean and build.
清洁和建造。
Recommended solution step by step:
逐步推荐的解决方案:
- Create splash image assets (name as LaunchImage) there in Image.assests folder.
- Select LaunchImage asset in Launch Image Sourceoption.
- And Clear the text in Launch screen Fileoption.
- Clean and build.
- Below is the reference image for right configuration:
- 在 Image.assests 文件夹中创建启动图像资产(名称为 LaunchImage)。
- 在Launch Image Source选项中选择 LaunchImage 资产。
- 并清除启动屏幕文件选项中的文本。
- 清洁和建造。
- 以下是正确配置的参考图像:
回答by Gordon
I had this problem in XCode 9.4.1, turned out to be caused by the assets folder not being included in the Bundle Resources. Select the project, then your target. Go to 'Build Phases' and open up 'Copy Bundle Resources'. If the .xcassets group you want to use isn't listed then just drag it in from the file browser.
我在 XCode 9.4.1 中遇到了这个问题,原来是由于资产文件夹未包含在捆绑资源中引起的。选择项目,然后选择目标。转到“构建阶段”并打开“复制捆绑资源”。如果未列出您要使用的 .xcassets 组,则只需将其从文件浏览器中拖入即可。
Worked for me...
为我工作...
回答by DanielWaw
After few hours of unclear answers:
1) go to setting app General section in xCode.
2) Scroll down to App Icons and Launch Images.
3) Clear Launch Screen File (just leave it blank)
4) Set Launch Images Source to LaunchImage (remember to create them in Assets.xcassets)
Now app will use images You set in LaunchImage.
经过几个小时的不清楚答案:
1)转到在 xCode 中设置应用程序常规部分。
2) 向下滚动到应用程序图标并启动图像。
3)清除启动屏幕文件(只需将其留空)
4)将启动图像源设置为LaunchImage(记住在Assets.xcassets中创建它们)
现在应用程序将使用您在LaunchImage中设置的图像。
回答by Viniciusoh
Had a similar issue today. Tried to let xCode create automatically the Asset, but it was always unassigned.
今天遇到了类似的问题。试图让 xCode 自动创建资产,但它始终未分配。
The solution was to create manually the Launch Image in the ImageAsset and assign the files for his respective resolution.
解决方案是在 ImageAsset 中手动创建启动图像,并为其各自的分辨率分配文件。
It looks like xCode created a different type of Launch Image asset, so it didn't recognized the asset (v8.3.2)
看起来 xCode 创建了不同类型的 Launch Image 资产,因此它无法识别该资产 (v8.3.2)
回答by Nik Kov
Solved!I've tried a lot. The problem was that the launch image shows in simulator and didn't show in real device. I got a Storyboard with UIImageView in it. Strange was that old images worked, and images, that i did add recently not. First i thought that this is a problem with assets. No. Than i checked color profiles and did a lot of tries with different profiles: left-working image, right-not working. Didn't help.
解决了!我已经尝试了很多。问题是启动图像显示在模拟器中而没有显示在真实设备中。我有一个带有 UIImageView 的 Storyboard。奇怪的是,旧图像有效,而我最近添加的图像却没有。首先我认为这是资产的问题。不。比我检查颜色配置文件并使用不同的配置文件做了很多尝试:左侧工作图像,右侧不工作。没有帮助。
Then i started google and found thisthread
然后我开始谷歌并找到了这个线程
Main solutions from here:
这里的主要解决方案:
1) Didn't helped for me.
1)对我没有帮助。
Change image property of my launch image using Preview app: [ Tools --> Assign Profile... --> ColorSync Profile: <> ]
使用预览应用程序更改我的启动图像的图像属性:[ 工具 --> 分配配置文件... --> ColorSync 配置文件:<> ]
2) Helped
2)帮助
Even deleting the app and re-installing from XCode doesn't work. However, changing the bundle ID does work. With no other changes, the existing bundle ID shows no images, but the new bundle ID shows them all correctly. I'm doing that as a temporary work-around, since a previous post in this thread suggests that installing the builds via TestFlight doesn't encounter the problem.
即使删除应用程序并从 XCode 重新安装也不起作用。但是,更改捆绑 ID 确实有效。在没有其他更改的情况下,现有包 ID 不显示图像,但新包 ID 会正确显示所有图像。我这样做是作为临时解决方法,因为此线程中的前一篇文章表明通过 TestFlight 安装构建不会遇到问题。
3)
3)
I did three things (the first two on their own didn't do it, but may have assisted the third which did work)
1) Copied all of the images to the root directory (same location as xcode puts the images)
2) Created a folder in Images.xcassets and put the images in there.
3) The images in the launchScreen.xib were originally called imageName.png. This was changed to just imageName (remove the file extension.After the third thing the images appeared. I don't know if either of the first two steps are required, but hopefully it will help someone.
我做了三件事(前两件事自己没有做,但可能帮助了第三件事)
1)将所有图像复制到根目录(与 xcode 放置图像的位置相同)
2)创建Images.xcassets 中的一个文件夹并将图像放在那里。
3)launchScreen.xib 中的图片原名为 imageName.png。这已更改为仅 imageName(删除文件扩展名。在第三件事之后,图像出现了。我不知道是否需要前两个步骤中的任何一个,但希望它会对某人有所帮助。
4) Helps but old and rude
4)帮助但又老又粗鲁
Taking the images out of the asset catalog fixed the problem for me. I just added the @1x, @2x, and @3x image used on my launch screen to the project the old way and it seems to be working fine. Trying to confirm it through TestFlight now, but iTunes Connect isn't behaving at the moment.
从资产目录中取出图像为我解决了这个问题。我刚刚以旧方式将启动屏幕上使用的 @1x、@2x 和 @3x 图像添加到项目中,它似乎工作正常。现在尝试通过 TestFlight 进行确认,但 iTunes Connect 目前不工作。
I thought this is an iPhone cash problem. So you don't need to warn about it thus the image will show when installing with testFlight. After this conclusion i did next and that worked:
我认为这是 iPhone 现金问题。所以你不需要警告它,因此在使用 testFlight 安装时会显示图像。在得出这个结论之后,我接下来做了,并且奏效了:
1) Uninstall app
2) Reboot phone
3) Build app to the phone
1) 卸载应用程序
2) 重启手机
3) 构建应用程序到手机
回答by DilumN
Close the simulator & open it again worked for me
关闭模拟器并再次打开它对我有用
回答by Prashant Tukadiya
I have face same issue.
我面临同样的问题。
In splash screen image is not displayingbut other thing like label and view are showing up correctly .
在启动画面中,图像未显示,但标签和视图等其他内容正确显示。
To fix issue first verify all of the above settings in your code. If nothing works then Restart the iPhonesolves my problem.
要解决问题,请首先验证代码中的所有上述设置。如果没有任何效果,则重新启动 iPhone可以解决我的问题。
Hope it is helpful to someone here (Happy to help) :)
希望对这里的人有帮助(很高兴能帮到你):)