简体   繁体   English

UIImageView在启动屏幕上是黑色的

[英]UIImageView is black on launch screen

I sometimes face a very strange issue on launch screen. 我有时在启动画面上遇到一个非常奇怪的问题。 I'm using a xib file with just a UIImageView on it, however sometimes the image is just a black rectangle. 我正在使用一个只带有UIImageView的xib文件,但有时图像只是一个黑色矩形。

I've tried to switch between .jpg and .png files but this didn't help, I've also assigned a different image property profile to it. 我试图在.jpg和.png文件之间切换,但这没有用,我还为它分配了一个不同的图像属性配置文件。

This happens on devices running iOS 9. 这种情况发生在运行iOS 9的设备上。

在此输入图像描述

These are the constraints for the UIImageView . 这些是UIImageView的约束。 I've removed the image, as it's a logo of a client. 我删除了图片,因为它是客户的徽标。

在此输入图像描述

在此输入图像描述

I have the same problem. 我也有同样的问题。 I've tried: 我试过了:

  • move the .png file to Images.xcassets. 将.png文件移动到Images.xcassets。 fail. 失败。
  • create a new LaunchFile.storyboard. 创建一个新的LaunchFile.storyboard。 fail. 失败。
  • rename the .png file. 重命名.png文件。 work for a while, but after you perform the Build&Run action(same with Run without building action) a few times, the issues occur again. 工作一段时间,但在执行Build&Run操作(与Run没有构建操作相同)几次后,问题再次发生。 very weird.(sometime you need to reopen the Xcode to reproduce the issue) 非常奇怪。(有时你需要重新打开Xcode来重现这个问题)
  • test the same LaunchFile.storyboard in a new project. 在新项目中测试相同的LaunchFile.storyboard。 the LaunchFile is correctly displayed in the new project, very confused me. LaunchFile在新项目中正确显示,让我很困惑。

Finally, i found a way which works not only for temporary(I've tested for one hour, just repeat build and run for like 100 times, watch TV meanwhile). 最后,我发现了一种不仅适用于临时工作的方式(我已经测试了一个小时,只需重复构建并运行100次,同时看电视)。

This issue is somehow related to the .png image. 此问题与.png图像有某种关联。 I dragged my .png file to photoshop, then go File > Save for web (Command + Option + Shift + S), make sure the transparency is unchecked, export a new .png file. 我将.png文件拖到photoshop,然后转到File> Save for web(Command + Option + Shift + S),确保未选中透明度,导出新的.png文件。 replace the old file with then new one you'll find the issue is fixed. 用新的文件替换旧文件,你会发现问题已修复。

But I'm still confused why a issued .png file can work for a while. 但我仍然困惑为什么发布的.png文件可以工作一段时间。

I have the same problem that appears from time to time on some devices. 我有一些设备上不时出现的问题。 Last thing that helped was a full restart of a device. 最后一件事就是完全重启设备。

Not sure what the original issue was really, I fixed it by manually generating legacy splash screens though. 不确定原始问题是什么,我通过手动生成传统启动屏幕来修复它。

One issue with debugging that may be helpful was that it persisted when updating the build (even when the app was deleted) until I both deleted the app and shut down the device. 调试可能有用的一个问题是,在更新构建时(即使应用程序被删除)它仍然存在,直到我删除应用程序并关闭设备。 I guess the splash screens are getting cached and so this clears the cache. 我猜飞溅屏幕正在缓存,因此清除了缓存。 I hope this helps save some folks some time, if anyone knows why this was happening, I'd still be happy to know. 我希望这有助于拯救一些人,如果有人知道为什么会这样,我仍然很高兴知道。

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

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