Swift programatic splash screen - ios

Is it possible to make the splashscreen/LaunchScreen programatically? And if so how?
I currently have a launchscreen.xib file. But I'd like to convert this into a .swift file with code instead.
However I havn't been able to find anything on how to do a launchscreen purely programatically.

The whole point of a launch screen is that it's shown before your code is ready to run. So that it can load quickly, it can only be an image or a xib.
You can certainly swap in a programmatic screen which looks the same after the launch screen shows, but you can't put code in that initial screen.

Related

Swift: Animation code on LaunchScreen [duplicate]

This question already has answers here:
iOS Launch screen code not running
(2 answers)
Closed 5 years ago.
I want to rotate an app logo on my Launch Screen (LaunchScreen.storyboard).
This link helps me in getting the code to rotate an image. However, where can I put this code?
Since there is no class file associated with the Launch Screen, how can I acheive this?
You can't directly do that as the launch screen is static. Even if it's set up via a .xib or a storyboard file, it will appear as a snapshot of the initial state of that scene.
You should create a view controller with the same look as your launch screen and animate that.
You can't achieve that. Before LaunchScreen.storyboard you was putting only static images in order to be shown on launch. LaunchScreen.storyboard is introduced later to simplify the generation of static images.
But you can kind of workaround it. You display exactly same looking view controller just after launchscreen and run animation. But there will be a little delay.

Activity View Indicator isn't animating at LaunchScreen.storyboard

I want to use Activity View Indicator on my app while it's loading, so I have LaunchScreen.storyboard.
I use "Behaviour - Animating" on my AVI, but it is not animating.
When I use Act.V.Indic. not in LaunchScreen - it is animating.
The LaunchScreen storyboard is static. iOS actually creates an image from the LaunchScreen and displays that image. It is impossible to have any dynamic or animated content in a LaunchScreen storyboard.
If your app takes time to load, then your app should display another screen as soon as it starts and that screen should show the activity indicator view.
Launch screens are static. Even though you set it to animating, it won't animate, simply because it can't. Think of them as outlines for your launch images. iOS will generate an image from them, that'll be shown to the user. They are a more convenient way of generating launch screens but aren't interactive or dynamic.

iOS Launch Screen Image not always showing

I use a Launch Screen (xib) in my app to overcome the problem of the resizeable screen, since i don't always want add Launchscreens everytime, Apple create a new iPhone with a different screen resolution.
In my launchscreen, i placed a UIImageView directly in the center of the view using constraints. The image shows the logo of the company i work for.
The problem is, that sometimes the image is being hidden (mostly after install and first launch) and sometimes it shows (mostly after a view times using it). I'm not quite sure, what the problem is. Is it because at the first-launch-time(s) it has to load many ressources?
Figured out the problem: It seems, that if there isn't enough disc space left on the device, it doesn't show the xib's (Launch-Screen's) Image. iOS at some point clears out some disc-space (i guess from NSLibraryDirectory) and than the images show again.
If this is a major problem to any of your apps, use Launch-Images instead.

Custom File for Launch Screen

I'm making an app where I need to program the launch screen, more than just placing images on the .xib file. Is there a way to connect a swift file to the launch screen so I can add animations?
I was thinking of doing something like Supercell does for Clash of Clans, where there's a loading bar and a short message users can look at while the game loads.
So is it possible to connect a swift class file to the .xib launch screen and how would one go about doing it?
Thanks
Unfortunately your app cannot process or display any animations during this launch screen. This is because the app is still technically loading.
Also it contradicts Apple's design guidelines for launch screens:
Design a plain launch image that improves the user experience. In
particular, the launch image isn’t an opportunity to provide:
An “app entry experience,” such as a splash screen
An About window
Branding elements, unless they are a static part of your app’s first
screen
What you can do is add your own custom "animation screen" as the entry point to your Storyboard (or just root view) and create animations as you normally would through a View Controller swift file.

iOS, change splash screen by code

Basically, I want my app could change its splash screen by app settings. Settings are saved in plist file.
Actually it's about different language, I want enable my user to choose my app language, even if it's different with the system preferred language.
Is it possible? I searched some answer, suggesting to use another view controller to simulate as splash screen, but my splash screen itself will take some to to load my app, not by my pause. So should I display nothing in the real splash screen?
I wonder if there is a way to change the splash screen by some conditions.
Thanks a guys.
The splash screen will show only for as long as it takes for the appDidFinishLoading method to return YES. One possible solution is for you to have a really simple (not localizable) splash screen and to basically do nothing in this method and return YES straight away.
You can then use an actual view controller as your splash screen that is dynamically initialized and actually does any initialization your app may need in the viewDidAppear method. Once the initialization is done, you can then proceed and show what would normally be your root view controller.
EDIT:
You should also consider, however, that splash screens are not intended to provide any kind of content to the user, as pointed out in this answer.
Apple does not provide a way to do that, as that would involve either modifying the Info.plist or modifying the splash images, both of which would in turn spoil your code signature. It would also open a very ugly can of worms, so modifying Info.plist will probably never be allowed which in turn means you will not be able to change the splash screen dynamically unless Apple adds explicit support for that via some other means. But right now, you're out of luck, I'm afraid.

Resources