简体   繁体   English

启动屏幕在 iOS 14 和 Xcode 12 上不起作用

[英]Launch Screen not working on iOS 14 with Xcode 12

I am very frustrated now.我现在非常沮丧。 I upgraded Xcode to version 12 and tested my app on iOS 14. Now the problem is, that my launch screen is just showing in black.我将 Xcode 升级到版本 12,并在 iOS 14 上测试了我的应用程序。现在的问题是,我的启动屏幕只是显示为黑色。 I tested it with an iOS 13.5 device and it is still working as expected.我使用 iOS 13.5 设备对其进行了测试,它仍然按预期工作。 I tried to remove the launchscreen.storyboard approach and added the Launch Screen key in the info.plist, but then the image is scaled to full size.我试图删除 launchscreen.storyboard 方法并在 info.plist 中添加了 Launch Screen 键,但随后图像被缩放到全尺寸。

Now I tested a little bit with the launchscreen.storyboard and I found a few things.现在我用launchscreen.storyboard测试了一下,我发现了一些东西。

  • If I remove the Image view, the launch screen is showing as expected.如果我删除图像视图,启动屏幕将按预期显示。 I added just a label and that would work.我只添加了一个 label 就可以了。
  • If I use an image from the system in the image view, it is working as well.如果我在图像视图中使用系统中的图像,它也可以正常工作。 It is just not working when I am using an image from the project.当我使用项目中的图像时,它只是不起作用。

Did you experience issues with iOS 14 and the storyboard approach?您是否遇到过使用 iOS 14 和 storyboard 方法的问题?

If yes, how did you fix it?如果是,您是如何解决的?

A work around that seems to be working for me:一个似乎对我有用的解决方法:

For a strange reason if I am downsizing the image then it is working fine .出于一个奇怪的原因,如果我缩小图像的大小,那么它工作正常 I had a full size image of dimension 2732x2732 and it didn't work.我有一个尺寸为 2732x2732 的全尺寸图像,但它不起作用。 Reducing the dimension of the same image to 2400x2400 is working fine.将同一图像的尺寸减小到 2400x2400 效果很好。 I have tried with 2500x2500 and 2600x2600 but none worked.我尝试过 2500x2500 和 2600x2600,但都没有奏效。

Most importantly, every time I change the image I had to restart the simulator to reflect the updated image.最重要的是,每次更改图像时,我都必须重新启动模拟器以反映更新后的图像。

It didn't work on the real device yet.它尚未在真实设备上运行。 Like the simulator, I had to restart the device and then only it worked.就像模拟器一样,我必须重新启动设备,然后才能正常工作。

Not sure if it is something with the dimension/size of the image or with the reboot.不确定它是否与图像的尺寸/大小或重新启动有关。

Further updates:进一步更新:

I uploaded the same build (with smaller image) to TestFlight and installed it on my device (basically updated from the previous version having large size image) and unfortunately the issue persisted :(我将相同的构建(带有较小的图像)上传到 TestFlight 并将其安装在我的设备上(基本上从具有大尺寸图像的先前版本更新),不幸的是问题仍然存在:(

Now what I did is uninstalled the app and reinstalled it again from TestFlight.现在我所做的是卸载应用程序并从 TestFlight 重新安装它。 Issue still persisted.问题仍然存在。

Finally I had to delete the app , reboot my device and install the app again.最后我不得不删除该应用程序重新启动我的设备并再次安装该应用程序 This is when it worked fine.这是它工作正常的时候。

So here are a lot of good ideas, but I was able to finally solve the issue - it is more like a workaround.所以这里有很多好主意,但我最终解决了这个问题——它更像是一种解决方法。 I needed to store the picture outside the Images.xcassets folder and then it started to work again.我需要将图片存储在 Images.xcassets 文件夹之外,然后它又开始工作了。 This is a very weird issue.这是一个非常奇怪的问题。

A workaround is to use a button with an image instead of an imageview in the launch storyboard.解决方法是在启动故事板中使用带有图像的按钮而不是图像视图。 It works like a charm!!它就像一个魅力!

The only workaround that works for me was to add the images outside Images.xcassets folder.唯一对我Images.xcassets解决方法是在Images.xcassets文件夹外添加图像。 After modified this and rebuild the app, it worked expected.修改此内容并重建应用程序后,它按预期工作。

Some issue it's happening on the iOS 14 or XCode 12.在 iOS 14 或 XCode 12 上发生了一些问题。

Had the same problem.有同样的问题。 The issue was the .png image used in the launch screen storyboard.问题在于启动屏幕故事板中使用的 .png 图像。 This lead to the whole launch screen just being black.这导致整个启动屏幕只是黑色。

What fixed it in our case was:在我们的案例中修复它的是:

  • Choose a smaller image选择较小的图像
  • Delete App from device/simulator从设备/模拟器中删除应用程序
  • Restart device/simulator重启设备/模拟器

I found that the image was the source of error by replacing the image with an other one in our app.通过在我们的应用程序中用另一个图像替换图像,我发现图像是错误的来源。 It immediately worked with a different image (no restarting or else required).它立即使用不同的图像(无需重新启动或其他需要)。

I encountered this problem我遇到了这个问题

when using LaunchScreen.storyboard and used the image on Assets.xcassets, not working on iOS 14 with Xcode 12.当使用 LaunchScreen.storyboard 并在 Assets.xcassets 上使用图像时,不适用于 iOS 14 和 Xcode 12。

I solved it by try put change 3x image 2436×1125,and set 2x image 828×1792.我通过尝试将更改 3x 图像 2436×1125 设置为 2x 图像 828×1792 来解决它。

Finally I had to delete the app, reboot my device and install the app again.最后我不得不删除该应用程序,重新启动我的设备并再次安装该应用程序。 This is when it worked fine.这是它工作正常的时候。

I had this, too.我也有这个。 Pretty infuriating.真气人。 My launch screen is merely a background image (2048x2048 PNG) and a graphic (2048x2048 PNG) in the middle.我的启动屏幕只是一个背景图像 (2048x2048 PNG) 和中间的图形 (2048x2048 PNG)。

The fix for me was to have a smaller middle graphic (720x720 PNG), remove the images from any assets catalogs, and add them into the project.对我来说,修复是使用较小的中间图形(720x720 PNG),从任何资产目录中删除图像,然后将它们添加到项目中。

The images didn't show on the Simulator until I restarted it.直到我重新启动它,图像才显示在模拟器上。 When built and installed to my iPhone, I didn't have to restart it.构建并安装到我的 iPhone 后,我不必重新启动它。

One reason might be the size of the images.原因之一可能是图像的大小。 Since iOS 14 images for launch screen are limited to 25 MB as stated in Apples Human Interface Guidelines .由于 iOS 14 启动屏幕图像限制为 25 MB,如 Apples Human Interface Guidelines 中所述

An image with 2.400x2.400 pixel will result in a memory size about 22 MB.具有 2.400x2.400 像素的图像将导致大约 22 MB 的内存大小。 With 2.500x2.500 we reach the 25 MB.使用 2.500x2.500,我们达到了 25 MB。

We had the same problem where the full screen image in LaunchScreen.storyboard was black on all @3x devices like iPhone 12. Reducing the size of only the @3x launch image from 3.072x3.072 to 2.400x2.400 solved this problem.我们遇到了同样的问题,其中LaunchScreen.storyboard中的全屏图像在 iPhone 12 等所有 @3x 设备上都是黑色的。将仅 @3x 启动图像的大小从 3.072x3.072 减小到 2.400x2.400 解决了这个问题。

A square image is the easy way to support landscape and portrait orientation.方形图像是支持横向和纵向方向的简单方法。 But it should also work to have different images for each orientation, where one image in total is less than 25 MB.但它也应该适用于每个方向的不同图像,其中一个图像总数小于 25 MB。

I have a similar issue with XCode12 / iOS14 and React project: The launchscreen.storyboard was working fine in previous versions.我在 XCode12/iOS14 和 React 项目中遇到了类似的问题:launchscreen.storyboard 在以前的版本中运行良好。 Since update to XCode12 it shows as following:由于更新到 XCode12,它显示如下:

  • Lauching into a black screen (2-3 seconds)启动进入黑屏(2-3 秒)
  • Then showing the Launchscreen correctly然后正确显示 Launchscreen

If I try to use the new "Launch Screen" dictionary in Info.plist I have the follwing issues (same in another Xamarin App):如果我尝试在 Info.plist 中使用新的“启动屏幕”字典,我会遇到以下问题(在另一个 Xamarin 应用程序中相同):

  • Image is zoomed in / not showing completely图像被放大/未完全显示
  • Background color setting is completely ignored (tried RGB and Color.xcasset)完全忽略背景颜色设置(尝试过 RGB 和 Color.xcasset)

This is just completely bugged since Xcode 12 !自 Xcode 12 以来,这完全被窃听了!

So I've had this bugged with Apple via their feedback system since June 26th 2020 - FB7795777.因此,自 2020 年 6 月 26 日起,我通过他们的反馈系统向 Apple 提出了这个问题 - FB7795777。

I've provided my project and many diagnostic reports and they've never come back with a fix.我提供了我的项目和许多诊断报告,但他们从来没有修复过。

However, today, I fixed it.但是,今天,我修复了它。

Basically, there has been some change in the iOS/iPadOS SDK about how it's support .PNG and .JPG files (size or dimensions are the problems I think) in the Launch screen process.基本上,iOS/iPadOS SDK 在启动屏幕过程中关于它如何支持 .PNG 和 .JPG 文件(我认为大小或尺寸是问题)发生了一些变化。

The solution:解决方案:

Open your .PNG file in Photoshop and re-export it with the 'Smaller File - 8-bit' option checked.在 Photoshop 中打开您的 .PNG 文件,并在选中“更小文件 - 8 位”选项的情况下重新导出它。 It shrunk it down to less than half the size, and it worked first time.它将它缩小到不到一半的大小,并且第一次起作用了。

In my case following did the job:-在我的情况下,以下工作完成了:-

  1. Remove Launch screen file from Project -> General -> App Icons and Launch Imagees -> Launch screen file.从项目中删除启动画面文件- >常规- >应用程序图标和启动Imagees - >启动画面文件。

  2. Go to info.plist file and open as source code.转到 info.plist 文件并作为源代码打开。

  3. Add following code there and change the image name:-在那里添加以下代码并更改图像名称:-

    <key>UILaunchScreen</key> <dict> <key>UIImageName</key> <string>splash(This is your image name)</string> </dict>

  4. In iOS 14 this new key was released (UILaunchScreen).在 iOS 14 中发布了这个新密钥 (UILaunchScreen)。 So take care from next time.所以下次要注意了。 If you get error then check info.plist file.如果出现错误,请检查 info.plist 文件。

  5. Happy coding :)快乐编码:)

In my case, the ViewController property, "Is Initial View Controller" was not checked.在我的情况下,未检查 ViewController 属性“是初始视图控制器”。 Also, be sure to set the color of the view to an actual color and not a system color, otherwise you can run into issues with the device theme settings.此外,请务必将视图的颜色设置为实际颜色而不是系统颜色,否则您可能会遇到设备主题设置的问题。 That is, if you like to show a specific color.也就是说,如果您想显示特定颜色。

Also, to access that setting make sure you click on the actual View Controller object in the drop down panel.此外,要访问该设置,请确保单击下拉面板中的实际视图控制器对象。 图像

That worked for me was:对我有用的是:

  1. Put xxx.pdf image into Assets.xcassets and set "scale" to Single Scalexxx.pdf图像放入 Assets.xcassets 并将“scale”设置为Single Scale

  2. In Launch Screen.storyboard, set the imageView's image is xxx , then set imageView 's width , height , centerX and Bottom to View在启动Screen.storyboard,设置ImageView的形象是XXX,则设置imageView宽度高度的centerX底部来查看

Then worked for me然后为我工作

Xcode 12.5.1, iPhone 7 Plus, iOS 14.6 Xcode 12.5.1、iPhone 7 Plus、iOS 14.6

In my own case , I solved the problem in these few steps:在我自己的情况下,我通过以下几个步骤解决了问题:

  1. Image must be 1024px, then图片必须是1024px,然后
  2. Add to assets添加到资产

-> A workaround in case you have a much bigger image, use these simple steps: -> 如果您有更大的图像,请使用以下简单步骤的解决方法:

  1. Generate your app icon生成您的应用程序图标
  2. Go to the app icon folder转到应用程序图标文件夹
  3. Copy the 1024 px of that image and appicon image复制该图像和appicon 图像的 1024 像素
  4. Then add to assets.然后添加到资产。 Both methods works perfectly.这两种方法都可以完美运行。

This may help others so I am adding it here.这可能对其他人有帮助,所以我在这里添加它。

I use Cordova for my hybrid app, and then I load my image assets that are generated by Asset Catalog Creator (which is a great little product).我将 Cordova 用于我的混合应用程序,然后加载由 Asset Catalog Creator(这是一个很棒的小产品)生成的图像资产。

This was working perfectly until I updated to Xcode 12 and tried to run it under iOS 14.在我更新到 Xcode 12 并尝试在 iOS 14 下运行它之前,这一直运行良好。

What I discovered is that Cordova was adding a "CDVLaunchScreen.storyboard", and they had a "LaunchStoryboard.imageset" (directory) in their asset catalog, which contained just a contents.json file.我发现 Cordova 正在添加一个“CDVLaunchScreen.storyboard”,并且他们的资产目录中有一个“LaunchStoryboard.imageset”(目录),其中只包含一个 contents.json 文件。

I simply copied this into my asset catalog, and when I drag and drop this into my updated project (newly generated each time by Cordova), my Launch Image displays again.我只是将它复制到我的资产目录中,当我将它拖放到我更新的项目(每次由 Cordova 新生成)时,我的启动图像再次显示。

Don't ask my how or why Xcode magically wires this stuff together, but it worked for me.不要问我 Xcode 如何或为什么神奇地将这些东西连接在一起,但它对我有用。

I can pass along the contents.json that worked with my asset catalog if it will help.如果有帮助,我可以传递与我的资产目录一起使用的 contents.json。

BTW, my General settings screen does NOT have a Launch Screen File selected, but Xcode seems to find the required files.顺便说一句,我的常规设置屏幕没有选择启动屏幕文件,但 Xcode 似乎找到了所需的文件。

I've got yet another potential solution to this, as none of the existing solutions worked for me.我还有另一个潜在的解决方案,因为现有的解决方案都不适用于我。

I use PDF vectors in my Asset file, and this normally works great.我在我的资产文件中使用 PDF 向量,这通常很好用。 But it turns out that it doesn't work on the launch screen - it just shows skips the launch screen entirely if it contains a PDF image.但事实证明它在启动屏幕上不起作用 - 如果它包含 PDF 图像,它只会显示完全跳过启动屏幕。

Swapped it for a large PNG, problem solved.把它换成一个大的 PNG,问题解决了。

The only thing that worked for me was:唯一对我有用的是:

  1. Delete the existing LaunchScreen.storyboard & create a new one删除现有的 LaunchScreen.storyboard 并创建一个新的
  2. Check " Use as Launch Screen "选中“用作启动屏幕”

用作启动屏幕

  1. Check " Is Initial View Controller "检查“是初始视图控制器”

初始视图控制器

  1. Make sure the image your using is NOT located under Assets.xcassets folder.确保您使用的图像不在 Assets.xcassets 文件夹下。 I put my image in the root of the project我把我的图片放在项目的根目录下
  2. Delete the app, restart the simulator, and run the application删除应用,重启模拟器,运行应用

BINGO!!!答对了!!!

What worked for me:什么对我有用:

  • Use smaller images like @Darkpaw suggested.使用建议的@Darkpaw 等较小的图像。 Launch storyboards are, after all, intended to be indicative of the coming UI, not artwork based.毕竟,发布故事板旨在指示即将到来的 UI,而不是基于艺术作品。
  • Use PNG image (not PDF) and don't put it in an assets catalog like suggested by @Sylber使用 PNG 图像(不是 PDF)并且不要像@Sylber 建议的那样将其放入资产目录中

Just noting separately as I had black/broken launch mages until I did BOTH steps.只是单独注意,因为我有黑色/损坏的发射法师,直到我完成了这两个步骤。

You might be seeing this issue if your @1x, @2x, @3x images are blank in your image xcassets folder.如果您的图像 xcassets 文件夹中的 @1x、@2x、@3x 图像为空白,您可能会看到此问题。

Make sure you have images for each.确保每个图像都有图像。

You can also select your 1 image, and set Scales as "Single Scale" in the Attributes inspector (on the right hand side)您还可以选择您的 1 个图像,并在属性检查器(右侧)中将比例设置为“单一比例”

In Xcode 13 launch screen was not displaying rather a black screen was coming.在 Xcode 13 中,启动屏幕没有显示,而是出现了黑屏。

But this worked for me Project -> General -> App Icons and Launch Images -> Launch screen file -> change Main to Launchscreen.但这对我有用项目->常规->应用程序图标和启动图像->启动屏幕文件->将Main更改为Launchscreen。

Most answers mentioned here are workarounds, the issue i noticed is that when you modify the launch screen assets, do check the item file name too.这里提到的大多数答案都是解决方法,我注意到的问题是,当您修改启动屏幕资产时,也要检查项目文件名。

Assets -> Show in folder资产 -> 在文件夹中显示

在此处输入图像描述

Then check the launchscreen items folder and make sure that the item inside the folder has the same name as folder.然后检查启动屏幕项目文件夹并确保文件夹内的项目与文件夹同名。

在此处输入图像描述

To expand on Thorsten Stark's answer above...要扩展上面的 Thorsten Stark 的答案......

Since iOS 14 images for launch screen are limited to 25 MB由于 iOS 启动屏幕的 14 个图像限制为 25 MB

For me it appeared to be an accumulated size of assets on my Launch Screen storyboard file.对我来说,这似乎是我的启动屏幕 storyboard 文件上资产的累积大小。 When I removed a number of them I no longer saw the black screen.当我删除其中一些时,我不再看到黑屏。

I ended up just using one image 2778 x 1284 which was 600kb in size.我最终只使用了一张 2778 x 1284 的图像,大小为 600kb。 This solved the problem.这解决了问题。

To further test, I duplicated the image to make 3 copies on my Launch Screen storyboard file, and sure enough, black screen again.为了进一步测试,我在我的启动屏幕 storyboard 文件上复制了图像以制作 3 个副本,果然,再次黑屏。

The best solution to me in 2022... 2022年对我来说最好的解决方案......

reduce sizes of your images, in my case: splash.png (256x256) splash@x2.png (512x512) splash@x3.png (768x768)减小图像的大小,在我的例子中: splash.png (256x256) splash@x2.png (512x512) splash@x3.png (768x768)

only doing this and put them in Resources folder then reference in ImageView work like charm....只这样做并将它们放在资源文件夹中,然后在 ImageView 中引用,就像魅力一样......

alternative: use Button in place of ImageView works too替代方案:使用 Button 代替 ImageView 也可以

I am very frustrated now.我现在很沮丧。 I upgraded Xcode to version 12 and tested my app on iOS 14. Now the problem is, that my launch screen is just showing in black.我将Xcode升级到版本12,并在iOS 14上测试了我的应用程序。现在的问题是,我的启动屏幕仅显示为黑色。 I tested it with an iOS 13.5 device and it is still working as expected.我已使用iOS 13.5设备对其进行了测试,但仍可以按预期运行。 I tried to remove the launchscreen.storyboard approach and added the Launch Screen key in the info.plist, but then the image is scaled to full size.我试图删除launchscreen.storyboard方法,并在info.plist中添加了Launch Screen键,但是随后将图像缩放为完整大小。

Now I tested a little bit with the launchscreen.storyboard and I found a few things.现在,我对launchscreen.storyboard进行了一些测试,发现了一些东西。

  • If I remove the Image view, the launch screen is showing as expected.如果删除“图像”视图,则启动屏幕将按预期显示。 I added just a label and that would work.我只添加了一个标签,就可以了。
  • If I use an image from the system in the image view, it is working as well.如果我在图像视图中使用系统中的图像,则它也可以正常工作。 It is just not working when I am using an image from the project.当我使用项目中的图像时,它只是无法正常工作。

Did you experience issues with iOS 14 and the storyboard approach?您是否遇到过iOS 14和情节提要方法的问题?

If yes, how did you fix it?如果是,您如何解决?

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

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