我正在尝试从我的启动屏幕中获得一个图像来显示为启动屏幕。故事板文件,但图像从不显示。我有标签显示良好,但图像不出现。

这是启动屏幕在启动屏幕中的外观。故事板文件:

然而,当我在模拟器(以及物理设备)上运行应用程序时,显示如下:

如您所见,标签“Test”显示良好,但图像没有显示。我真的不知道为什么会发生这种情况,我尝试的任何方法似乎都不起作用。如果任何人有任何关于如何解决这个问题的想法,这将是非常感激的。


当前回答

到目前为止,有视网膜设备可用,我忽略了Assets.xcassets中的@1x图像。

在我的情况下,我有应用程序的logo在启动屏幕是不可见的,当我运行应用程序。

在浪费了这么多时间后,我发现我只提供了@2x和@3x图像的标志图像。

通过添加该图像的@1x版本,可以解决此问题。

其他回答

当使用launch-storyboard显示启动画面时,我也遇到了同样的问题,经过研究,我发现我在launch-storyboard中设置的图像大小不同,我设置的图像视图比图像的实际大小更大。

所以我找到的解决方案是设置图像-视图内容大小为方面适合或设置图像-视图大小为图像大小。

比如,如果你的图像@1x的大小是200X200,那么图像视图应该是200X200,那么你就可以解决这个问题。

因为如果你设置图像视图的大小大于图像,那么图像将被上浆,这是不允许的。

如果你还有任何疑问,请在这里评论并询问

在投入了大量的时间后,我得到了解决方案:-

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 

有同样的问题,将图像添加到“构建阶段->复制捆绑资源”为我修复了它。

在我的情况下,重置模拟器的内容和设置解决了这个问题。

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. Also, before adding your image, you have to make sure that the image file is in your "Assets.xcassets" folder within your project. 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.