iOS 8:启动屏幕 StoryBoard 显示为黑色 [单个 XIB 文件工作正常]
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31676901/
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
iOS 8: Launch Screen StoryBoard appears black [single XIB file works fine]
提问by Darvish Kamalia
So I tried creating a launch storyboard for my iOS 8 app using this tutorial
所以我尝试使用本教程为我的 iOS 8 应用程序创建一个启动故事板
However, I only get a black screen when I launch my app. A single launch screen.xib file works perfectly, however, when I try to use a storyboard, it doesn't work.
但是,当我启动我的应用程序时,我只会出现黑屏。单个启动 screen.xib 文件运行良好,但是,当我尝试使用故事板时,它不起作用。
I tried a storyboard with just a single view controller, but it still gives me a black screen, hence I believe the issue is with storyboard files in my setup. Any ideas?
我尝试了一个只有一个视图控制器的故事板,但它仍然给我一个黑屏,因此我相信问题在于我的设置中的故事板文件。有任何想法吗?
[XCode version 6.4]
[XCode 6.4 版]
EDIT: So I just want to clarify that it is the launch screen that appears black. The main storyboard itself appears correctly when the app has finished loading
编辑:所以我只想澄清一下,它是显示为黑色的启动屏幕。应用程序加载完成后,主故事板本身会正确显示
回答by CraftMcMatt
Read through the tutorial and tested it, and it doesn't say two things:
通读教程并测试它,它没有说两件事:
1: You'll need to add a UIViewController
to your .storyboard
file, and then select it as the Initial Controller.
1:您需要UIViewController
在.storyboard
文件中添加一个,然后选择它作为初始控制器。
2: If you wish to change more than just the launch screen, you'll have to go to the project settings and set the "Main Interface" to your corresponding .storyboard
.
2:如果您想更改的不仅仅是启动屏幕,您必须转到项目设置并将“主界面”设置为相应的.storyboard
.
Once that is done, all you need to do is edit the UIButton/Label/etc connections to your ViewController classes.
完成后,您需要做的就是编辑 UIButton/Label/etc 与 ViewController 类的连接。
EDIT:
编辑:
For clarification, you can set a UIView as the initial controller by selecting it in it's respective storyboard file, then opening the Attributes Inspector. The option for 'Is Initial Controller" is towards the middle.
为了澄清起见,您可以通过在其各自的故事板文件中选择 UIView 来将其设置为初始控制器,然后打开 Attributes Inspector。“是初始控制器”的选项位于中间。
回答by Ehtesham Hasan
For people using UIImageView in the launch screen
对于在启动屏幕中使用 UIImageView 的人
Make sure that you are using the image name without the extensionin the attributes inspector.
确保您在属性检查器中使用没有扩展名的图像名称。
So for example, if your image file is named launcher.png
, only use launcher
as image name.
例如,如果您的图像文件名为launcher.png
,则仅用launcher
作图像名称。
This will show the image as invalid (?) in the editor but will show correctly when run on device.
这将在编辑器中将图像显示为无效 (?),但在设备上运行时将正确显示。
(Don't ask me why it works this way. Ask Apple.)
(不要问我为什么这样工作。问 Apple。)
回答by SwiftArchitect
None of the answers have all the steps required, hence this exhaustive solution.
没有一个答案包含所需的所有步骤,因此这是一个详尽的解决方案。
Storyboard
故事板
Start by creating the LaunchScreen.storyboard. Xcode > File > New > File... > Storyboard > LaunchScreen.storyboard and add it to all appropriate targets.
In this storyboard, create a single view controller of type UIViewController
. Do all the magic your launch screen requires, then follow these steps:
首先创建LaunchScreen.storyboard。Xcode > File > New > File... > Storyboard > LaunchScreen.storyboard 并将其添加到所有适当的目标。
在这个故事板中,创建一个类型为 的视图控制器UIViewController
。执行启动屏幕所需的所有魔法,然后按照以下步骤操作:
LaunchScreen.storyboard
> Show the File inspector > Use as Launch ScreenLaunchScreen.storyboard
> View Controller > Show the Attributes inspector > Is Initial View Controller- Project > General > Deployment Info > Main Interface > LaunchScreen
Repeat for [iPhone] and [iPad] - Project > General > App Icons and Launch Images > Launch Screen File > LaunchScreen
If setup properly, your Info.plistshould have LaunchScreen.storyboard, without the .storyboardunder the
UILaunchStoryboardName
&UIMainStoryboardFile
properties:<key>UILaunchStoryboardName</key> <string>LaunchScreen</string> <key>UIMainStoryboardFile</key> <string>LaunchScreen</string>
LaunchScreen.storyboard
> 显示文件检查器 >用作启动屏幕LaunchScreen.storyboard
> 视图控制器 > 显示属性检查器 >是初始视图控制器- 项目 > 常规 > 部署信息 > 主界面 >
[iPhone] 和 [iPad] 的LaunchScreen
重复 - 项目 > 常规 > 应用程序图标和启动图像 > 启动屏幕文件 > LaunchScreen
如果设置正确,您的Info.plist应该有LaunchScreen .storyboard,而在&属性下没有.storyboard:
UILaunchStoryboardName
UIMainStoryboardFile
<key>UILaunchStoryboardName</key> <string>LaunchScreen</string> <key>UIMainStoryboardFile</key> <string>LaunchScreen</string>
Notes:
笔记:
- This is notincompatible with having legacy images for older devices using Launch Screen File > Assets.
- Pay special attention to
LaunchScreen.storyboard
andMain.storyboard
. One is used for launch, the other for your app entry point. They both need to have Is Initial View Controllerset.
- 这与使用 Launch Screen File > Assets为旧设备提供旧图像并不不兼容。
- 特别注意
LaunchScreen.storyboard
和Main.storyboard
。一个用于启动,另一个用于您的应用程序入口点。他们都需要设置初始视图控制器。
回答by Davinder Singh
In the storyboard, which you are using for launching, please make sure that you had selected the option of Is initial view controllerfor the very single view controller present in it.
在您用于启动的故事板中,请确保您为其中存在的单个视图控制器选择了初始视图控制器选项。
回答by Dom Bryan
I Belive I may have had a similar issue that required something a littel different to the above answers.
我相信我可能有一个类似的问题,需要一些与上述答案不同的东西。
I created a new launch screen in a .storyboard file, then after it not appearing I resulted to a new .xib file which still did not appear when the app was launched.
我在 .storyboard 文件中创建了一个新的启动屏幕,然后在它没有出现之后我产生了一个新的 .xib 文件,该文件在应用程序启动时仍然没有出现。
I figured out that some of the images I had on my launch screen had an Outlet Collection to an old .swift file. After removing this from the LaunchScree.xib's the launch screen worked fine.
我发现我的启动屏幕上的一些图像有一个旧的 .swift 文件的 Outlet Collection。从 LaunchScree.xib 中删除它后,启动屏幕工作正常。
回答by amergin
Spent way too long on this, thanks Apple! I finally discovered that I had to delete the actual UIImageView in my view controller - not just the image - in order to change to a different image. Tried renaming the images, replacing them in all different ways, deleting caches, deleting the app from the device, doing a Clean before building. The original image was gone from everywhere as far as I could see but it would still appear. Finally I added a new UIImageView on top in the view controller and this took a new image. Then I just deleted the old UIImageView and all was fine.
在这上面花了太长时间,感谢 Apple!我终于发现我必须删除视图控制器中的实际 UIImageView - 不仅仅是图像 - 才能更改为不同的图像。尝试重命名图像,以各种不同的方式替换它们,删除缓存,从设备中删除应用程序,在构建之前进行清理。就我所见,原始图像从任何地方消失了,但它仍然会出现。最后,我在视图控制器的顶部添加了一个新的 UIImageView 并拍摄了一张新图像。然后我只是删除了旧的 UIImageView,一切都很好。
回答by MazzaMan
Make sure that you set your entry point and in your general info tap make sure that you have the view set to resize from nib. Also make sure that in your general tab the start up point is set. In the deployment info.
确保您设置了入口点,并在您的一般信息中点击确保您将视图设置为从笔尖调整大小。还要确保在您的常规选项卡中设置了启动点。在部署信息中。
Hope this helps
希望这可以帮助
回答by Valentin Shamardin
I had the black screen instead of my splash after localizing my app. In Localization section of the File inspector of LaunchScreen.storyboard I had only one tick for one localization. So, I added a tick for the second localization and this fixed the issue.
本地化我的应用程序后,我看到了黑屏而不是飞溅。在 LaunchScreen.storyboard 的文件检查器的本地化部分,我只有一个本地化的勾号。所以,我为第二个本地化添加了一个勾号,这解决了这个问题。
回答by kennymuse
The solution is use the image name without the extension png.
解决方案是使用不带扩展名 png 的图像名称。
For example, if your image file is named "img.png", only use "img".
例如,如果您的图像文件名为“img.png”,则仅使用“img”。
This will show the image as invalid (?) in the editor but will show correctly on running.
这将在编辑器中将图像显示为无效 (?),但会在运行时正确显示。
This happen because the LaunchScreen.storyboard accept only images inside Assets.xcassets and the way to refer the images inside Assets.xcassets is the name of the resource without extension.
发生这种情况是因为 LaunchScreen.storyboard 仅接受 Assets.xcassets 中的图像,并且引用 Assets.xcassets 中图像的方式是不带扩展名的资源名称。
I think that use the name without extension is a workaround that work.
我认为使用不带扩展名的名称是一种可行的解决方法。