Execute Code in Launch Screen UPDATED - ios

Execute Code in Launch Screen ORIGINAL
Now that the default LaunchScreen file in Xcode projects have been changed from .xib to .storyboard files (just like Main.storyboard), is it now possible to design the launch screen programmatically if you choose to?
Can you write custom code for the launch screen?

It is not possible to write any custom class/code for the launchscreen xib/storyboard files. We can only design using resource files.

Completely Agree with Arun Ammannaya. I ran a test to verify it and here is the result.

Yes, its possible to write ViewController for the launch screen,
1) Create viewController file, create Xib for the same.
2) In the RootViewController's (say HomeViewController or SignInViewController) ViewDidLoad(),
2a) Create object of SplashViewController.
2b) Add view of splashViewController to your HomeViewController.
let objSplashVC = yourCode to create object of SplashVC
self.view.addSubView(objSplashVC.view);
c) After 2 or 3 seconds or once your retrieve data on Web-Service call, you can remove that view, by calling hide() method of SplashViewController
hide(){
self.view.removeFromSuperView();
}
Note : You have to add background image on SplashViewController as same as launchImage. So transitions will go smoothly.

Related

Add a Launch Screen to the iOS App in Code in Swift (without Storyboard or Launchboard)

I created my views in code. The starting point is the didFinishLaunchWithOptions function in the Appdelegate class.
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
let controller = ViewController() // create an instance of my ViewController and set it to the rootViewController
window?.rootViewController = controller
I would like to add a launch screen that appears instantly when your app starts up. The launch screen should be quickly replaced with the first screen of the app, giving the impression that your app is fast and responsive. I found some answers that said it is not possible(Is there any way to code the LaunchScreen programmatically). My idea was creating a new launchView and replace it through NSTimer. Isn't there any easier or alternative way ?
Thanks
This is not possible as such as the Launch Screen is not a regular View Controller and it cannot hold any logic. Any animations which are there in the App during startup are handled after the launch Screen has appeared and the animations are in the root view controller as in Twitter app. If you are completely against using launch Screens then an alternative would be make a view in IB and use its screenShot as a splashImage. There is no way as of now to make a launchScreen programatically or to add any logic to it.

iOS app launches to black view

I have been trying to run my Xcode project on my iOS simulator an iPhone but I only get a black screen. I have tried multiple solutions but none seem to work.
I have tried:
Setting main interface to "Main.storyboard"
Installing all views i.e.: width: any, height: any
Adding print statement to viewDidLoad to state that the view did in fact load (didn't print that the view loaded)
Resetting all content of the iOS simulator
Running on my iPhone
Setting initial view controller
None of these have solved my problem
Make sure in your AppDelegate that you are creating the variable window like so (right after the app delegate class declaration): var window: UIWindow?.
Without this line of code, your views will just never launch and your screen will stay black.
There might be many reasons for blank black view. But first check whether you have the window variable declared in your appDelegate as suggested by #john. If this doesnt work, check in the storyboard whether you have made your first controller as initial view controller.
You can also do this by adding rootviewController as the view controller you want in the window inside application:didFinishLaunchingWithOptions:
May be you use an empty UIViewController(). In my case I set a default value an empty UIViewController()

storyboard or rootViewcontroller, which goes first

At the launching phrase of an App, which controller would it use as the rootviewcontroller for it's window (while they both exist)? the one declared in AppDelegate or the one used in Storyboard?
If nothing is declared in AppDelegate, would the App create a UIWindow for it's .window property by default and make the entry viewController in the designated storyboard it's rootViewController?
If nothing added in applicationDidLuanch: delegate Method for creating a new window, so your app create your UIWindow and make the root is the root in your storyboard file, but if you want to create custom starting point, add another storyboard or even a single .xib file as your staring point and let your appDelegate know your starting point.

Switching View in methods in XCode 4

I am using XCode 4.4 and making an app with storyboard.
I want to switch to another view in a method of a view.
I want to achieve the same functionality as switching
view on storyboard by modal,inside the method.
So far I am using the following code:
-(IBAction)xplus:(id)sender
{
x++;
if(x>30)
{
ViewController_2 *viewControllerx = [[ViewController_2 alloc] init];
[self presentViewController:viewControllerx animated:YES completion:nil];
}
}
When the view is supposed to change ie when x becomes greater than 30
a Black Screen appears instead of the required view. I personally think my code is correct but why it shows a black screen?
How can I to achieve the same functionality as switching view on storyboard by modal,inside the method ?
Your method is not working out probably because you are not not using the .xib file with the view controller that you want to go to and using storyboard.
Anyways let me give you an easy and efficient method to perform the task.
Step 1: Go to storyboard of your project and click on the View Controller to which you want to go in your method i.e. ViewController_2.Click on the inspector icon(It is the 4th one). In the identifier field type a name eg: second.
Step 2: Use the following lines in your method to create a instance of ViewController_2 using the initiateViewControllerWithIdentifier method and to modal to it.
ViewController_2 *v2=[self.storyboard initiateViewControllerWithIdentifier:#"second"]; [self presentModalViewController:v2.animated:YES];
Now the app will go to(create instance of) the ViewController having the same Identifier as the one given as argument i.e. second.

iOS Splash Page while Loading Data

I am trying to write an app that displays a simple logo/splash page while the app retrieves some data. I cannot seem to find a tutorial anywhere.
I have a "MainWindow.xib" file that will have my splash page, and I'm setting that as my "Main Interface" in my Info.plist, however, I cannot seem to see how to replace that page with a .xib that contains a UINavigationController. I thought I would just create a new UIController, that had a UINavigationController and in my .xib I'll drag in a Navigation Controller and set all my information, but it's giving me real fits.
So, I figured I would have a UIController that I would "alloc" and "init" with my second .xib that contains all my navigation.
myMainController = [[UIController alloc] initWithNibName:#"MainNavController":nil];
in "MainNavController.xib", I've dragged in a Navigation Controller, but I don't know what to connect it to????
I'm sure I'm going down the wrong, path; but I cannot find a decent tutorial for this.
Can someone give direction or link to a decent tutorial?
Thanks.
Are you ever actually adding the new controller to your existing view? If not, something like:
[self.view addSubview:myMainController.view];
should do it for you. A better alternative is likely to be:
self.window.rootViewController = myMainController;
But I'm fairly new to this and maybe I've missed something ...
To display a splash screen while the app is loading you can use Default.png image file.
However, I think your question is how to display another splash screen for a period of time after the app has been loaded.
In you MainWindow.xib keep your window separated from your Navigation Controller. Add your splash screen view with an image to the xib.
Make two outlets: one for slash view, one for Navigation Controller.
IBOutlet UIView* _spashScreenView;
IBOutlet UINavigationController* _navigationController;
In applicationDidFinishLaunching method add your splash screen view to the window.
[_window addSubview:_spashScreenView];
// lay it out
When you are ready to display your navigation controller:
[_spashScreenView removeFromSuperView];
[_window addSubview:_navigationController];

Resources