UIImageView在设备上的启动屏幕中丢失图像

本文翻译自:UIImageView missing images in Launch Screen on device

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). 我有一个支持iOS8及更高版本的应用程序,内置Xcode 7,我使用XIB作为启动屏幕(我没有启动图像)。 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. 该视图包含一个带有应用程序版本的UILabel,以及两个带有图像的UIImageViews,这两个图像都存在于Images.xcassets中:一个徽标和一个启动图像。

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. 启动应用程序时,UILabel和徽标图像显示正确,但如果我在带有iOS9的iPad Air 2上运行应用程序,则不会显示启动图像。 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. 我已经在Air和Mini上测试过运行iOS8,以及适用于iPad 2,iPad Air和iPad Air 2的iOS9模拟器,所有这些都能正确显示图像。

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. 启动图像的UIImageView位于正确的位置,大小正确。 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. 将启动图像的UIImageView设置为也使用徽标图像可使徽标图像显示在视图的正确位置。 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). 我在启动图像视图中使用的UIImage在应用程序的其他地方使用,在其他视图中显示得很好(徽标图像也在应用程序的其他地方使用,看起来很好)。 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. 我已经确认xcassets文件中徽标和启动的UIImages设置是相同的。 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). 有一个区别 - 徽标有1x,2x和3x刻度,而初始图像只有1x和2x,但我也试过在UIView中只使用1x,1x和2x值的UIImages它们可以工作(如果它们是不久前加入了该项目)。

  • 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. 将另一个不同大小或格式的图像(PNG和JPG)添加到我的xcassets并在UIImageView中使用该UIImage作为启动图像也无法显示。

  • 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. 将另一个UIImageView添加到XIB文件并为其分配已在xcassets中运行的UIImage,图像将显示在加载屏幕中。

  • 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. 复制和重命名用于徽标的图像文件并将其添加到项目中,然后在启动视图中使用该UIImage也无法显示。

  • 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. 我已经尝试清理项目,重新启动开发机器,并从Air 2中删除应用程序并重新安装它以防万一出现问题。

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. 当我昨天更新到Xcode 7时,初始图像最初是在Xcode 6中添加的,但是几个月之前添加了徽标图像(也在Xcode 6中添加)。

I've looked over the json files for the logo image and splash image and they appear to have the same format. 我查看了json文件中的徽标图像和启动图像,它们看起来格式相同。 I've also trawled through the pbxproj file looking for differences and I can't see any. 我还浏览了pbxproj文件,寻找差异,我看不到任何差异。

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? 所以我想知道是否有人知道为什么发射屏幕可能无法显示我在Air 2上特别添加的这些新图像? 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. 我一直在阅读的有关未出现的图像的其他问题似乎与启动图像或与具有关联类的XIB文件中的图像有关,这两者似乎都不相关。


#1楼

参考:https://stackoom.com/question/2ChKA/UIImageView在设备上的启动屏幕中丢失图像


#2楼

I had exactly the same issue on an iPhone 6. 我在iPhone 6上遇到了完全相同的问题。

The very strange fact is that I was able to use another image from my images.xcassets which had the same size, compression, color space ... 非常奇怪的事实是我能够使用我的images.xcassets中的另一个图像,它具有相同的大小,压缩,颜色空间......

I'm not able to find why it doesn't work but I found a solution : Simply put your file outside your images.xcassets and use its full name (with extension) in Interface Builder 我无法找到它为什么不起作用但我找到了一个解决方案:只需将您的文件放在images.xcassets之外,并在Interface Builder中使用其全名(带扩展名)

故事板样本中的splashScreen

Hope this help ! 希望这有帮助!


#3楼

I also had this exact problem in Xcode 7 with iPad and iPhone devices. 我也在Xcode 7中使用iPad和iPhone设备遇到了这个问题。 Although it makes no sense, I was able to get around it most of the time by setting not only the Image but also the Highlighted image in the image view to the same image in my images.xcassets. 虽然没有意义,但我能够通过将图像视图中的图像和高亮显示的图像设置为我的images.xcassets中的相同图像来大部分时间绕过它。


#4楼

Turn if off and then on again. 关闭然后再打开。

Seriously, restart the device — that's what fixed it for me. 说真的,重新启动设备 - 这就是为我修复它的原因。

Here's what didn't work: 这是不起作用的:

  • Cleaning DerivedData 清理DerivedData
  • Cleaning the project 清洁项目
  • Uninstalling the app from the device 从设备卸载应用程序
  • Restarting Xcode 重启Xcode
  • Restarting the computer 重新启动计算机

Older observations: 较旧的观察:

Just like the others, it: 就像其他人一样,它:

  • Works fine in the Simulator 在模拟器中正常工作
  • Used to work on the devices (iPhone 5S, iPad Air) 用于在设备上工作(iPhone 5S,iPad Air)
  • No code changes (verified via git reset --hard HEAD), yet stopped working. 没有代码更改(通过git reset --hard HEAD验证),但已停止工作。

What I remember triggering the first build where it stopped working was unplugging the iPhone while it was runnning. 我记得当它停止工作时触发第一个构建是在iPhone运行时拔掉它。 (Not sure if it's related.) (不确定它是否相关。)

However, the git reset not fixing it (combined with all the clean steps not working) tells me it this must be getting cached somewhere else. 但是,git重置没有修复它(结合所有干净的步骤不起作用)告诉我它必须在其他地方缓存。 Quite possibly in one of the .gitignored files? 很可能在一个.gitignored文件中? (I'm using Git ignore file for Xcode projects ) (我正在使用Git忽略文件进行Xcode项目

One workaround that worked for one UIImageView (in the UIView that has three) but not for the others was putting the image into an .xcassets file. 对于一个UIImageView(在UIView中有三个)但不适用于其他UIImageView的一种解决方法是将图像放入.xcassets文件中。 Reverting to the plain image file did not undo the fix. 恢复到普通图像文件没有撤消修复。 (Really feels like a caching error.) (真的感觉像是一个缓存错误。)

UPDATE: See top — restarting the device is what fixed it. 更新:请参阅顶部 - 重启设备是什么修复它。 I get the feeling the wrong bitmap data is being cached on the device itself. 我感觉错误的位图数据正缓存在设备本身上。

Radar: http://openradar.appspot.com/23534818 雷达: http//openradar.appspot.com/23534818


#5楼

I was seeing the same problem. 我看到了同样的问题。 Rebooting the device (iPhone 6) and rebuilding the app to the device is the only thing that fixed it. 重新启动设备(iPhone 6)并将应用程序重建到设备是修复它的唯一方法。 I tried many other tips and suggestions but nothing else worked. 我尝试了许多其他提示和建议,但没有其他工作。 Only reboot + rebuild helped. 只有reboot + rebuild有帮助。


#6楼

I was having the same problem, but restarting the device didn't help. 我遇到了同样的问题,但重新启动设备没有帮助。 What worked for me was deleting the UIImageView from my launch storyboard and adding a new one. 对我有用的是从我的发布故事板中删除UIImageView并添加一个新的故事板。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值