UIImageView 在设备上的启动屏幕中缺少图像 [英] UIImageView missing images in Launch Screen on device

查看:12
本文介绍了UIImageView 在设备上的启动屏幕中缺少图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个支持 iOS8 及更高版本的应用程序,内置于 Xcode 7 中,我正在使用 XIB 作为启动屏幕(我没有启动图像).该视图包含一个带有应用程序版本的 UILabel,以及 2 个带有图像的 UIImageView,它们都存在于 Images.xcassets 中:一个徽标和一个启动图像.

当我启动应用程序时,UILabel 和徽标图像正确显示,但如果我在装有 iOS9 的 iPad Air 2 上运行应用程序,则启动图像不会.我已经在运行 iOS8 的 Air 和 Mini 以及适用于 iPad 2、iPad Air 和 iPad Air 2 的 iOS9 模拟器上进行了测试,并且图像在所有这些模拟器中都正确显示.

我进行了一些基本的故障排除,看看我是否能弄清楚发生了什么,但我无法解决它,我能看到的唯一区别是正常工作的图像和失败的图像是 我将它添加到资产...

以下是我所知道的概要:

  • 初始图像的 UIImageView 位于正确的位置,大小正确.我可以这么说,因为我将它的背景颜色设置为绿色只是为了确保.视图在那里,但图像没有出现.所以我假设观点不应该受到指责.

  • 将初始图像的 UIImageView 设置为也使用徽标图像会使徽标图像出现在视图的正确位置.这也让我认为观点不应该受到指责.

  • 我在启动图像视图中使用的 UIImage 在应用程序的其他地方使用,并且在其他视图中显示良好(徽标图像也在应用程序的其他地方使用并且显示良好).所以我假设图像是有效的并且让它出现在其他视图中是没有问题的.

  • 我已经确认 xcassets 文件中 logo 和 splash 的 UIImages 设置是相同的.它们设置为通用、任意宽度和高度、多个比例因子,默认呈现.有一个区别 - 徽标有 1x、2x 和 3x 比例,而初始图像只有 1x 和 2x,但我也尝试在 UIView 中使用只有 1x、1x 和 2x 值的 UIImages,它们可以工作(如果它们是前段时间添加到项目中).

  • 向我的 xcassets 添加另一个不同大小或格式(PNG 和 JPG)的图像并在 UIImageView 中使用该 UIImage 作为初始图像也无法显示.

  • 将另一个 UIImageView 添加到 XIB 文件并为其分配一个已经在 xcassets 中的 UIImage 工作,图像出现在加载屏幕中.

  • 复制和重命名用于徽标的图像文件并将它们添加到项目中,然后在启动视图中使用该 UIImage 也无法显示.

  • 我已尝试清理项目,重新启动开发机器,并从 Air 2 中删除应用并重新安装,以防万一出现问题.

最后三个步骤让我相信在项目文件生命周期的某个时间点之后添加的图像存在一些问题.虽然我昨天更新到 Xcode 7,但初始图像最初是在 Xcode 6 中添加的,但徽标图像(也在 Xcode 6 中添加)是几个月前添加的.

我查看了徽标图像和启动图像的 json 文件,它们似乎具有相同的格式.我还浏览了 pbxproj 文件以寻找差异,但我看不到任何差异.

所以我想知道是否有人知道为什么启动屏幕可能不显示我专门添加到 Air 2 上的这些新图像?我一直在阅读的与未出现的图像有关的其他问题似乎都与启动图像或具有关联类的 XIB 文件中的图像有关,这两者似乎都不相关.

解决方案

对我来说,解决方案只是确保未选中情节提要中 UIImageView 的清除图形上下文"框.只需更改此设置即可我."没有其他解决方案对我有用.从

I have an app that supports iOS8 and later, built in Xcode 7 and I am using a XIB for a Launch Screen (I do not have launch images). The view contains a single UILabel with the app version, and 2 UIImageViews with images that are both present in Images.xcassets: A logo and a splash image.

The UILabel and the logo image appear correctly when I launch the application, but the splash image does not if I run the app on an iPad Air 2 with iOS9. I have tested on an Air and a Mini running iOS8, and iOS9 simulators for iPad 2, iPad Air, and iPad Air 2 and the image appears correctly in all of those.

I ran some basic troubleshooting to see if I could figure out what is going on but I haven't been able to solve it and the only difference I can see between the image that's working and the one that's failing is when I added it to the assets...

Here's a rundown of what I know:

  • The UIImageView for the splash image is in the correct place, at the correct size. I can tell this because I set its background color to green just to make sure. The view is there, but the image does not appear. So I'm assuming that the view is not to blame.

  • Setting the UIImageView for the splash image to also use the logo image makes the logo image appear in the correct place for the view. This also leads me to assume that the view is not to blame.

  • The UIImage that I am using in the splash image view is used elsewhere in the app and appears fine in those other views (the logo image is also used elsewhere in the app and appears fine). So I'm assuming that the image is valid and having it appear in other views is not a problem.

  • I've confirmed that the settings of the UIImages for the logo and splash in the xcassets file are the same. They are set to Universal, Any width and height, multiple scale factors, rendered as default. There is one difference - the logo has 1x, 2x and 3x scales while the splash image only has 1x and 2x, but I have also tried using UIImages with only 1x, and 1x and 2x values in the UIView and they work (if they were added to the project some time ago).

  • Adding another image of a different size or format (PNG and JPG) to my xcassets and using that UIImage in the UIImageView for the splash image also fails to display.

  • Adding another UIImageView to the XIB file and allocating it a UIImage that was already in the xcassets works, the image appears in the loading screen.

  • Copying and renaming the image files used for the logo and adding them to the project then using that UIImage in the splash view also fails to display.

  • I have tried cleaning the project, restarting the development machine, and deleting the app from the Air 2 and reinstalling it just in case that was a problem.

These last three steps lead me to believe that there's some issue with images added after a certain point in the project file's lifetime. While I updated to Xcode 7 yesterday, the splash image was originally added in Xcode 6, but the logo image (also added in Xcode 6) was added some months before.

I've looked over the json files for the logo image and splash image and they appear to have the same format. I've also trawled through the pbxproj file looking for differences and I can't see any.

So I was wondering if anyone had any idea why the launch screen might not display these new images I'm adding on the Air 2 specifically? Other questions I've been reading through relating to images not appearing all seem to relate either to Launch Images, or to images in XIB files that have associated classes, neither of which seems relevant here.

解决方案

"The solution for me was simply to make sure that the "Clears Graphics Context" box is unchecked for the UIImageView in the storyboard. Just changing this fixed it for me." No other solutions worked for me. Got it from apple developer forum

这篇关于UIImageView 在设备上的启动屏幕中缺少图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆