[英]Launch Screen storyboard not displaying image
I'm trying to get an image to display as the launch screen from my Launch Screen.storyboard file, however the image never displays.我试图从我的 Launch Screen.storyboard 文件中获取一张图像作为启动屏幕显示,但该图像从未显示。 I have labels that show up fine, but the image doesn't appear.
我的标签显示正常,但图像不显示。
This is how the launch screen looks in the Launch Screen.storyboard file:这是启动屏幕在 Launch Screen.storyboard 文件中的样子:
However when I run the app on the simulator (as well as on the physical device) this is what shows up:但是,当我在模拟器(以及物理设备)上运行该应用程序时,会显示以下内容:
As you can see, the label "Test" shows up fine, however the image does not display.如您所见,label“测试”显示正常,但图像不显示。 I'm really not sure why this is happening and nothing I try seems to work.
我真的不确定为什么会这样,而且我尝试的任何方法似乎都不起作用。 If anyone has any ideas of how to fix this it would be greatly appreciated.
如果有人对如何解决此问题有任何想法,将不胜感激。
After restarting Xcode, cleaning the build and a number of the other suggestions on SO about this problem.重新启动 Xcode 后,清理构建和一些关于此问题的其他建议。 What actually fixed it for me was a hard reboot of the device.
实际上为我修复的是设备的硬重启。 (I wasted over an hour on this)
(我浪费了一个多小时)
I suppose it just goes to show that the old saying have you turned it off and on again is still true for the latest gadgets!我想这只是表明,对于最新的小工具来说,您是否将其关闭并再次打开这句老话仍然适用!
How to reboot iPhone XS or iPhone XS Max如何重启 iPhone XS 或 iPhone XS Max
I was messing around with this for hours too.我也在这个问题上折腾了好几个小时。 But i found the solution now.
但我现在找到了解决方案。 You need to add the image to your project and also to the assets.xcassets via drag and drop.
您需要将图像添加到您的项目以及通过拖放操作添加到 assets.xcassets 中。
有同样的问题,将图像添加到“构建阶段 - > 复制捆绑资源”为我修复了它。
Follow below steps,按照以下步骤,
If not working, delete derived data.如果不起作用,请删除派生数据。 Xcode Preference->Locationtab->Derived data.
Xcode Preference->Locationtab->Derived data。 Then do follow above steps.
然后按照上面的步骤操作。
It happened to me and makes me crazy, beyond get me lose some minutes 'til I figure it out.它发生在我身上,让我发疯,除了让我失去几分钟,直到我弄清楚为止。
So, like was said before:所以,就像之前说的:
On the design screen, it will not appear, but when you run your app, it will be shown.在设计屏幕上,它不会出现,但是当您运行您的应用程序时,它会显示出来。
I hope it can help!我希望它可以帮助!
Very frustrating.非常令人沮丧。 Solution that finally worked:
最终奏效的解决方案:
Do hard reboot of device硬重启设备
Delete app删除应用
Install app from Xcode从 Xcode 安装应用程序
At last, restart the phone works for me!!最后,重启手机对我有用!!
I have spent hours on this issue.我在这个问题上花了几个小时。 Had tried change the images name, delete the whole image assets, modify info.plist, restart Xcode and even tried to set all the attributes of the images(which you can tell how desperate I was).
曾尝试更改图像名称,删除整个图像资产,修改 info.plist,重新启动 Xcode,甚至尝试设置图像的所有属性(您可以看出我有多绝望)。
I faced the same problem.我遇到了同样的问题。
After invested a lot of time, I got the solution:-投入了大量时间后,我得到了解决方案:-
Step 1:- Quit Xcode
Step 2:- Delete the app from device/simulator
Step 3:- Restart your device (if you are using simulator then you have to quit simulator)
Step 4:- Clear all derived data
Step 5:- Clear Bin
Step 6:- Open Xcode and relaunch the app, it will work
此问题与Assets.xcassets相关以修复它您必须将图像添加为资源但不在xcassets文件夹中,然后应该可以正常工作
就我而言,重置模拟器的内容和设置解决了这个问题。
It seems there is some problem with resource caching in xCode. xCode 中的资源缓存似乎存在一些问题。 Had the same problem, restarted xCode and everything works fine after that.
有同样的问题,重新启动 xCode,之后一切正常。
重新启动您的设备并清除 x-code 派生数据
After trying everything on several StackOverflow threads, here's what worked for me:在几个 StackOverflow 线程上尝试了一切之后,这对我有用:
(Might have to clean product or derived data to update, but I didn't have to) (可能必须清理产品或派生数据才能更新,但我不必这样做)
Well As of now there is retina device available and I ignored @1x
image in Assets.xcassets
.到目前为止,有可用的视网膜设备,我忽略了
Assets.xcassets
@1x
图像。
In my case, I have app logo in Splash screen which is not visible when I run the application.就我而言,我在启动屏幕中有应用程序徽标,当我运行应用程序时该徽标不可见。
After wasting so much time I figured out that I only provided @2x
and @3x
images for that logo image.浪费了这么多时间后,我发现我只为该徽标图像提供了
@2x
和@3x
图像。
This issue is resolved by adding
@1x
version of that image.此问题已通过添加该图像的
@1x
版本解决。
在将图像添加到项目并击落问题解决的设备后,我遇到了这个问题
Was changing the background image of the splash screen and the new image wasn't showing (react native project).正在更改初始屏幕的背景图像,但未显示新图像(反应本机项目)。
Following the answers from others.遵循其他人的答案。
I did all the below and it was fixed:我做了下面的所有事情,它被修复了:
You have to make sure that the file name of your image has a format like .png or .jpg at the end otherwise it will not work.您必须确保图像的文件名末尾是 .png 或 .jpg 格式,否则将无法使用。 Also, before adding your image, you have to make sure that the image file is in your "Assets.xcassets" folder within your project.
此外,在添加图像之前,您必须确保图像文件位于项目中的“Assets.xcassets”文件夹中。 This can be done with a simple drag and drop.
这可以通过简单的拖放来完成。 Also, make sure when you've added your image to your storyboard that the image name in the top left also matches the real image file name.
此外,确保将图像添加到故事板后,左上角的图像名称也与真实图像文件名匹配。 I would try looking into Constraints too.
我也会尝试研究约束。 Hope this helps.
希望这会有所帮助。 Good luck with your App.
祝你的应用程序好运。
I tried so many things with this (this thread alone seems to have a million ideas and half of them are conflicting).我为此尝试了很多东西(仅此线程似乎就有一百万个想法,其中一半是相互冲突的)。 The problem for me was that when I did things like restarting the device and Xcode, it would cause the image to show for a few sessions of the app, and then it would stop (I have no idea why, but WOW it was annoying).
对我来说的问题是,当我执行诸如重新启动设备和 Xcode 之类的操作时,它会导致图像在应用程序的几个会话中显示,然后它会停止(我不知道为什么,但是哇,这很烦人) .
After countless hours, I found that AG's answer in this thread is the correct one.无数个小时后,我发现AG在此线程中的答案是正确的。 The one thing I was doing wrong was that I was creating a new image set within xcassets, but I was then still using the name of the image within the UIImageView inside of the storyboard instead of using the name of the image set.
我做错的一件事是我在 xcassets 中创建了一个新的图像集,但是我仍然在故事板内的 UIImageView 中使用图像的名称,而不是使用图像集的名称。
To clarify, what you would do is create a new image set and name it something like "Launch-Defaults", and then add your images to it.澄清一下,您要做的是创建一个新图像集并将其命名为“Launch-Defaults”,然后将您的图像添加到其中。 Then, within the UIImageView inside of the storyboard, you use the image "Launch-Default" (not including an extension since there is none since this is an image set).
然后,在故事板内的 UIImageView 中,您使用图像“Launch-Default”(不包括扩展名,因为这是一个图像集,因此没有扩展名)。
When you do all of that, the image should actually appear correctly inside of your storyboard.完成所有这些操作后,图像实际上应该正确显示在故事板中。 Some people say the image will display blank if you don't use the extension (.jpg or .png), but I assume that is because they are not using the name of the image set.
有人说如果不使用扩展名(.jpg 或 .png),图像将显示为空白,但我认为这是因为他们没有使用图像集的名称。 Others say you need to use an extension like .png or .jpg, but the key is to create the image set inside of xcassets and then use that image set inside of the storyboard.
其他人说您需要使用像 .png 或 .jpg 这样的扩展名,但关键是在 xcassets 内创建图像集,然后在故事板内使用该图像集。 When done correctly, there should be no funkiness like an image not showing up or the Launch Screen only working some of the time (requiring a reboot).
正确完成后,不应出现图像未显示或启动屏幕仅在某些时候工作(需要重新启动)之类的怪异现象。
Just to add my $0.02 to this question;只是在这个问题上加上我的 0.02 美元; I got this solved by using PNG images instead of JPG/JPEG images.
我通过使用 PNG 图像而不是 JPG/JPEG 图像解决了这个问题。
After converting the images to PNG and crunching them to reduce the size a little, everything worked fine.将图像转换为 PNG 并对其进行处理以稍微减小尺寸后,一切正常。
In my particular case, the splash screen worked for the simulator and other devices, but stopped working for one specific device.在我的特殊情况下,启动画面适用于模拟器和其他设备,但停止适用于一种特定设备。 This lead me to believe that it was some caching data kept by xcode (v10 and iPhone 7 v12.1).
这让我相信这是 xcode(v10 和 iPhone 7 v12.1)保存的一些缓存数据。
I deleted the derived data at: ~/Library/Developer/Xcode/DerivedData/
only emptying the folder contents, not deleting the folder.我删除了派生数据:
~/Library/Developer/Xcode/DerivedData/
只清空文件夹内容,不删除文件夹。 I then rebooted the mac and the iPhone and cleaned and rebuilt the project, and now it is showing up.然后我重新启动了 mac 和 iPhone,清理并重建了项目,现在它出现了。
I'm not sure if all of this was necessary, but didn't want to waste any more time narrowing it down, so the above sledgehammer approach worked for me.我不确定所有这些是否必要,但不想再浪费时间缩小范围,所以上述大锤方法对我有用。 But of course it always depends on your specific situation - mine was device specific;
但当然,这始终取决于您的具体情况——我的是特定于设备的; for others it could be the actual image or launch screen layout etc.
对于其他人,它可能是实际图像或启动屏幕布局等。
My issue.我的问题。
Reason: I have renamed the images after dragging into Xcode.原因:我在拖入 Xcode 后重命名了图像。 Solution: Don't rename images after dragging into Xcode.
解决方案:拖入Xcode后不要重命名图像。 It creates problems for understanding Xcode.
它为理解 Xcode 带来了问题。 Rename images before dragging/adding into Xcode.
在拖动/添加到 Xcode 之前重命名图像。
Hope it helps you out!希望能帮到你!
Actually, for some heavyweight images, it isn't a good situation to add them into images.xcassets
, because the app loads images.xcassets
lightweight images before launch.实际上,对于一些重量级图片,将它们添加到
images.xcassets
并不是一个好情况,因为应用程序在启动之前加载了images.xcassets
轻量级图片。 So I put splash screen images at the first root of load and then the issue has gone:所以我将启动画面图像放在加载的第一个根目录,然后问题就消失了:
xib
(or storyboard) file and address the ImageView to the special name that it is in step 3 .xib
(或故事板)文件并将ImageView寻址到它在步骤3 中的特殊名称。 Hint : You can create your ImageSet in the images.xcassets
but place them in the root of the project.提示:您可以在
images.xcassets
创建您的ImageSet ,但将它们放在项目的根目录中。
I spent hours on this problem before finally realizing my mistake.在终于意识到我的错误之前,我在这个问题上花了几个小时。 When you add an image to a UIImageView, it will use just the name of the image.
当您将图像添加到 UIImageView 时,它将仅使用图像的名称。 If your images are in a different folder than your storyboard, they will show up in xcode but not when running the app.
如果您的图像与故事板位于不同的文件夹中,它们将显示在 xcode 中,但不会在运行应用程序时显示。 You must add the appropriate file path prefix, for example, images/image.png.
您必须添加适当的文件路径前缀,例如,images/image.png。 It will now appear as a blue question mark in xcode, but it will work in the app.
它现在将在 xcode 中显示为蓝色问号,但它可以在应用程序中使用。
I faced the same issue.我遇到了同样的问题。 Tried different solutions for that but nothing proved to be helpful.
为此尝试了不同的解决方案,但事实证明没有任何帮助。 I then realised that the image was not visible only when i directly installed the app into device and the app is still connected to the xcode.
然后我意识到只有当我将应用程序直接安装到设备中并且应用程序仍然连接到 xcode 时,图像才可见。 If i disconnect it and then open the app the image was visible as expected.
如果我断开它然后打开应用程序,图像会按预期显示。 It might be a xcode bug.
这可能是一个 xcode 错误。
I tried cleaning the project, removing the png, removing the constraints did not work for me.我尝试清理项目,删除 png,删除约束对我不起作用。
I just made one more copy of the image and renamed the copy then deleted the old image and added the new image (Same, with name changed) i just gave that image and it worked for me.我只是制作了图像的另一个副本并重命名了副本,然后删除了旧图像并添加了新图像(相同,名称已更改)我只是提供了该图像并且它对我有用。
Also i am not using the Assets.xcassets, using the image in a folder.此外,我没有使用 Assets.xcassets,而是使用文件夹中的图像。
My first mistake was, that I created a normal .storyboard, renamed it and defined it as launchscreen in the project settings.我的第一个错误是,我创建了一个普通的 .storyboard,将其重命名并在项目设置中将其定义为启动屏幕。 I this case I had image problems.
在这种情况下,我遇到了图像问题。 It seems that some settings are missing in this case then, so I just created a new file via file->new and picked directly the "Launch Screen" and then it worked.
在这种情况下,似乎缺少一些设置,所以我只是通过 file->new 创建了一个新文件,并直接选择了“启动屏幕”,然后它就可以工作了。
Also I had in mind that, that layout constraints are not supported in the launchscreen for some reason.我还记得,出于某种原因,启动屏幕不支持布局约束。 Maybe it was like that in the beginning, not sure, but now constraints should work.
也许一开始就是这样,不确定,但现在约束应该起作用了。
Maybe this helps anyone.也许这对任何人都有帮助。
In my case, it was a bit more than just rebooting the device.就我而言,这不仅仅是重新启动设备。 My launch image was stored in other Assets (Other Pods).
我的启动图像存储在其他资产(其他 Pod)中。
Had to move the image to App project's Assets.必须将图像移动到 App 项目的资产。 And then rebooted my device.
然后重新启动我的设备。 (Check simulator first, it should work).
(首先检查模拟器,它应该可以工作)。 Then it worked.
然后它起作用了。
Images can be in format png/pdf, single scale or not doesn't matter.图像可以是 png/pdf 格式,单一比例与否无关紧要。
I was stucked into same issue thanks to the below reference I am able to resolve the issue由于以下参考,我陷入了同样的问题,我能够解决这个问题
https://developer.apple.com/forums/thread/19759?answerId=75438022#75438022 https://developer.apple.com/forums/thread/19759?answerId=75438022#75438022
Though it is not necessary to change the image name and removing the extension while selecting the image for imageview, I simply created one folder named resources and added my image inside that folder coz I thought it would be not good to put images directly into the root folder虽然在为 imageview 选择图像时没有必要更改图像名称和删除扩展名,但我只是创建了一个名为 resources 的文件夹并将我的图像添加到该文件夹中因为我认为将图像直接放入根目录并不好文件夹
Hope this would help.希望这会有所帮助。
Happy Debugging!调试愉快!
I just figured this out.我只是想通了这一点。 My launch image was not showing up, I get a white screen when launching on a device (iPhone 6, 7+) or testFlight.
我的启动图像没有显示,在设备(iPhone 6、7+)或 testFlight 上启动时出现白屏。 Fix: Renamed "Landing_screen.png" to just "Landing_screen" removing .png part.
修复:将“Landing_screen.png”重命名为“Landing_screen”,删除了 .png 部分。 The image icon in Xcode changed to white icon and in the launch screen storyboard the image appears as a question mark now.
Xcode 中的图像图标更改为白色图标,并且在启动屏幕故事板中,图像现在显示为问号。 The Launch image now appears and not the white screen.
现在出现启动图像而不是白屏。 My Setup: I am using Swift 3.1 with Xcode 8.3.1.
我的设置:我使用 Swift 3.1 和 Xcode 8.3.1。 In LaunchScreen.storyboard I added a simple image view and stretched the image to fit the view controller.
在 LaunchScreen.storyboard 中,我添加了一个简单的图像视图并拉伸图像以适应视图控制器。 I set auto layout constraints Top/Bottom/Leading/Trailing space to superview to 0 - see image below:
我将自动布局约束顶部/底部/前导/尾随空间设置为 0 - 见下图:
In my case, it turned out I had some views still linked to the view controller that was now just a basic view controller.就我而言,事实证明我有一些视图仍然链接到视图控制器,现在只是一个基本的视图控制器。 If I control-click on the view I can see the outlets with warnings, however, the warnings did not appear in Xcode which is why I was having trouble finding them.
如果我控制单击视图,我可以看到带有警告的插座,但是,警告没有出现在 Xcode 中,这就是我无法找到它们的原因。
这恰好是XCode / iOS中的缓存问题,但是有一个简单的解决方法:只需在Assets.xcassets中重命名文件,就可以重新生成缓存。
I have face this same issue when using launch-storyboard for showing splash screen and after research i have found that the image what i have set in launch-storyboard is of different size and i have set image-view bigger than actual size of image. 使用启动故事板显示初始屏幕时我也遇到了同样的问题,经过研究,我发现我在启动故事板中设置的图像大小不同,并且我将图像视图设置为大于实际图像大小。
So the solution i have found is either set image-view content size as aspect fit or set image-view size as image size. 因此,我发现的解决方案是将图像视图内容大小设置为高宽比,或者将图像视图大小设置为图像大小。
Like if your image @1x size is 200X200 than image view should be of 200X200 than you will solve this issue. 就像您的图像@ 1x大小为200X200时,图像视图应该为200X200时,您将解决此问题。
As because if you set image-view size bigger than image then image will starched and this is not allowed. 因为如果您将图像视图的尺寸设置为大于图像,则图像会出现糊状现象,这是不允许的。
If you still have any doubt please comment here and ask 如果您仍有任何疑问,请在此处评论并询问
I had launch screen file named but it didn't exist.我有命名的启动屏幕文件,但它不存在。 When I removed this my launch image appeared.
当我删除它时,我的启动图像出现了。
In my case I could fix it by just unchecking "clears graphics context" from attribute inspector for all of the image views used in the Launchscreen storyboard.在我的情况下,我可以通过从属性检查器中取消选中 Launchscreen 故事板中使用的所有图像视图的“清除图形上下文”来修复它。
For your information i had imported images in Assets.xcassets in png formats.为了您的信息,我在 Assets.xcassets 中以 png 格式导入了图像。
There was 2 issues in my case that resolved it:在我的案例中有两个问题解决了它:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.