設備上的啓動屏幕中的 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 和 2 個帶有圖像的 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.我已經在運行 iOS8 的 Air 和 Mini 以及適用於 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 中使用 UIImages 僅具有 1x、1x 和 2x 值,並且它們可以工作(如果它們是前段時間添加到項目中)。

  • 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 文件中具有關聯類的圖像有關,這兩者在這裏似乎都不相關。


解決方案:

參考一: https://en.stackoom.com/question/2ChKA
參考二: https://stackoom.com/question/2ChKA
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章