ChatGPT解决这个技术问题 Extra ChatGPT

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). 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.

Been meaning to reply on this - I came back and read over the answers provided, then returned to Xcode and re-adedd the UIImageView and image in order to try them out. This time, it worked without any changes. I have no clue why - same version of Xcode, I restarted, rebuilt, cleaned and removed the app before, same iOS, same Mac OS, it just worked. So unfortunately I haven't been able to verify if any of the solutions would have helped.
For me NONE of the provided answers solved the problem. Simulator, iPhone 5, iPhone 5 SE, iPad 4 are all displaying the UIImageView within my LaunchScreen.xib correctly, iPad Air 2 won't show it. Rebooted all devices, re-installed on all devices. Behaviour remains.
Hey you should accept the 130+ voted answer.
I agree with Khanh, it is working for most!!
@MFW, ACCEPT THE ANSWER FFS! IM REPORTING U TO THE COPS.

C
Community

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

Cleaning the project

Uninstalling the app from the device

Restarting 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)

No code changes (verified via git reset --hard HEAD), yet stopped working.

What I remember triggering the first build where it stopped working was unplugging the iPhone while it was runnning. (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. Quite possibly in one of the .gitignored files? (I’m using Git ignore file for Xcode projects)

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. 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


Simply restarting the simulator did it for me. Crazy!
Thank you! This fixed it for me as well.
Do you think App Store users are going to experience the same problem?
@danielstorm never found out to be honest
What a retarded bug, gg apple. Resarting my phone worked for me, thanks.
B
BananaNeil

"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

https://i.stack.imgur.com/01zB1.png


Damn, I never would have thought to try this. Fixes Simulator and Device with Xcode 7.3.1 (7D1014) and iOS 9.3.2 Developer Beta 3.
I can confirm this also worked for me. Xcode 7.3 and iOS 9.3.2.
Even with mine already checked -- unchecking and rechecking did the trick!
Nice +1 for your answer , works in Xcode 8 and iOS 10 as well
This is the correct answer. Proved on iOS 11, on device.
g
gbitaudeau

I had exactly the same issue on an 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 ...

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

https://i.stack.imgur.com/t2teu.png

Hope this help !


That was the first thing I tried, but it doesn't work for me.
This worked for me; thanks. I wish I knew why it was only working for some images in xcassets files though...
This works for me to begin with, but now the image or label properties are not updated at all. Even after a clean product action. Filed a bug here: bugreport.apple.com
Restarting the iPhone 6s after deletion of the app did the job. Prior to that NikLanf solution below "clears Graphics Context" was also check.
This works. The reason is I think due to .xcasset is yet not loaded when the launchscreen is shown. If you think about it, that is what launchscreen is for - a waiting time for ios to load app content, which includes xcasset. My guess is putting it outside works since everything in root folder of app will be loaded first.
m
mayankk2308

The following sequence of operations fixed the issue for me on Xcode 7.3.1 and iOS 9.3.4:

Clean Your Build (⌘+⇧+K) Close Xcode Hard Reset iOS Device (Power + Home Button reboot) Relaunch Xcode - let indexing finish and build on device once it is ready.


Saved my day! Thanks!
Worked. I did not do steps 2 and 4, Perhaps only a Hard Reset of the iOS device is needed, can anyone confirm this?
@TimothyL.J.Stewart Steps 2 and 4 were just more precautionary steps that I had taken because the issue was quite an annoyance for me - so it was just to be sure. I think you're right in saying they might be unnecessary since they do not really (typically) affect the build.
Xcode 8 Swift 3.0 Powering off or Hard Resetting is the only thing that works every time, and must be done every time a new asset is added. Deleting DerivedData does not. However, the image works properly in the simulator. This has wasted so much of my time, thank you @MayankKumar for the solution.
Worked like a charm
C
Community

Many other answers suggest rebooting devices and / or rebuilding and / or reinstalling is the solution.

While these answers work for some of us, the reason these work is because the app is forced to "retake" or "rebuild" cached snapshots.

Cached snapshots are used by apps to present images before supporting data is loaded into memory, including the asset catalogue that contains storyboard images.

This SO answer by @jaga provides the solution, but not the reason, as to why UIImageViews are missing in the Launch Screen on device (but not in the simulator).

Background

Recently I attempted to use a custom font in my "Launch Screen.storyboard" file.

The reason I could not became clear after reading this SO answer by @TimCamber, which prompted me to do a little more research and testing.

The reason that a custom font is not included in my Launch Screen Storyboard file is the same reason an image within an asset catalogue is not included...

The app prepares portrait & landscape snapshots of the app's Launch Screen from your Launch Screen Storyboard file and (currently) saves it in your app bundle here:

/Library/Caches/Snapshots/<>/ and

/Library/Caches/Snapshots/<>/downscaled/.

This process is complete before any supporting files are loaded, including any custom fonts and the asset catalogue.

Solution

As mentioned above by following @jaga's solution, literally all that is required is to:

(old school) add an image file (.PNG) to your app's bundle (as you can see from the screenshot below I added the image file under the Supporting Files subdirectory in an Images subdirectory), and

https://i.stack.imgur.com/1URfZ.png

reference that image in your UIImageView object in the Launch Screen Storyboard file...

https://i.stack.imgur.com/rIXsn.png


Thank I've been wrestling with this for a little while. That works for me.
worked for me directly. this should be the correct answer
On Launch IOS was not able to compile assets so placing your image to bundle works. Thanks.
Best answer so far. I will add this: the image has to be in the app-bundle's root directory. Otherwise you have to give the full path "Media/launch_v1_200_mod.png" if you store images in a sub dir.
I did the same. My app is already live but the issue is sometimes it is showing the image and sometimes it shows square with white color in the middle of the screen
B
Bruce L

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. I tried many other tips and suggestions but nothing else worked. Only reboot + rebuild helped.


How will it look like if the user will update the app from the AppStore? Will he need to reboot his device ?
K
Ke Yang

My solution @iOS 11.x:

Use .jpg image instead of .png. I think image file size matters;

(Optionally) Put image file in project directory rather than .xcassets;


Putting the image file outside of .xcassets helped
@Husam I really think it’s file size that only matters. I have a launch screen with two images: a large one (400+KB .png) and a logo (10+KB .png, inside .xcassets). The logo always show up normally, but the large one doesn’t.
You are right .. After my comment the issue appeared again after adding another image. Thanks for your help
Then followed your instructions by using jpg image and worked
What if you need transparency?
P
Petro Shm

I had the same for app installed from TestFlight. Delete app -> then restart iPhone -> then reinstall app works for me. Just reinstall app or just restarting device didn't help.


This is the only thing that worked for me - wish I had seen this 90 minutes ago !
wish I had seen this 4 hours ago
Worked for me as well, but the problem is weird :|
a
andynil

What worked for me was to select Reset Content and Settings... from the Simulator menu

https://i.stack.imgur.com/i1KmV.png


Three years later and this is what fixed it for me. It is now Device > Erase All Content and Settings...
J
Jim Rhoades

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.


J
Jakub Truhlář

Have you tried turning the device off and on again? Do it.


T
Trinh Tran

Bring images out of Image.xcassets and add them again to project. It worked for me.


That works only because you are forcing the app to recreate the Launch Screen snapshots, but it is not a solution to or reason for the problem.
m
midhun p

Remove app from mobile and then restart mobile and install app again. now the issues will be solved


b
bonnie lapin

I also had this exact problem in Xcode 7 with iPad and iPhone devices. 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.


Seems to be helped for me too
g
guozqzzu

I use the iPhone 5s device, also meet this problem.

I fix it by :

Remove Drive Data Clean the project Restart Xcode Remove the project from my device Restart the 5s.

I think it's something wrong of Xcode to use memory, system may be allocate a little memory for Xcode cause Xcode drawing the lunch image failed (On my computer , Xcode have runned for several weeks without close)


I do not know, but it worked.. like good. Thanksw man for sharing.
o
oscar castellon

it's worked for me.

First in xcode clean de project.

If you use the simulator, delete app and relaunch.

If you use a device, delete app and restart the device.


S
Sunly

I think launchscreen only support image in Assets.xcassets.


I tried all the answers above and none of them worked for me. But this answer solved the issue.
M
Manuel

Restarting Xcode did it for me.

What did not do it:

Clean build folder

Restart device or simulator (image wasn't visible on either)


A
Asha Antony

Select the ImageView and then remove the image extension (.png or .jpg) in the attributes inspector tab > Image view > Image > Image Name.

On launchscreen.storyboard the image will not appear but it will be there in device. This worked for me.


This was my problem too. Strangely it randomly worked on some devices. Xamarin-Project with Xcode 9.4 for XIB/Storyboard editing...
A
Amon Xu

It seemed a bug of iOS. Like sometimes the system animation disappeared.

Now I just reboot the iPhone and it is worked for me.


d
de.

In my case I it was the image name.
I added an image named Default-568h@2x.png to LaunchScreen.xib - one of my old launch screens just for testing purposes. I was building on the iPhone X Simulator, the image didn't show up.

Changing the name to something neutral (MyImage.png) solved the issue.

It seems that the @2x was part of the problem as well as the -568h. Which makes some sense on a -812h@3x device.


o
ostap_holub

I have the same issue with imageView a launch screen storyboard. I removed reference of picture from project, I renamed my image and added it again to project. All works perfectly.


J
Jesse

Also can 1. delete project image 2. change image name 3. add file image to project

It worked for me.


J
JamieDass

I had this problem in iOS 10 on an iPhone 6 and also in the Simulator. My image was in a folder and that seemed to be the issue. I removed the image from the folder in Xcode and put it in the project's base directory which solved the problem.


T
Tim Le

I experience the same. I change image resolution from 300 pixels/inch, change it to 72. It works for me.


V
Vladimir Tolstikov

Next helped to me:

change "Launch Screen File" to another xib

run the app

change xib back

Also very important: check that your is xib not opened in another tab, that can cause it as well!


F
Fox5150

I found a simple but radical solution that worked for me :

1 - Delete the file : LaunchScreen.storyboard and move it to trash.

2 - Product -> Clean

3 - Create a new launch screen file named : LaunchScreen.storyboard and put your images in it

4 - Save and build

That worked for me after trying complex methods for hours... It seems that my LaunchScreen.storyboard was write-locked and couldn't be saved or a weird caching process was blocking it.


S
SwiftDeveloper

This is too important Must be empty! Launch Screen File

https://i.stack.imgur.com/sptmP.png


He's using the XIB storyboard for launching, this answer will not work.
A
Aproram

Image name is the problem. Rename the image name used inside the Launch screen storyboard. Make sure not to use any character other than alphanumeric ( don't use "_-&@") Worked for me like a charm..


z
zx485

SOLVED!

The only thing that worked for me was deleting the ViewController from LaunchScreen.storyboard and create a new ViewController set to

Is Initial View Controller

Simple as that :)