Possible to have a different iOS splash screen on first load? - ios

Would it be possible to show a different splash screen (launch image) on the first load of an application?
For example the first load would have a text ("Please wait while we setup your app..."), while the following loads would have another splash screen (no text for example).

No this is not possible, since you can not change the launch image because the main bundle is read only.
You could however present a view controller just after your application is started and have the text in this view.
Just return as soon as possible from the application:didFinishLaunchingWithOptions: and only load the view controller with the text in this method.
Then start doing what ever your app need to do, and dismiss the view controller when done.

No, the default image is there at a time when your app isn't yet executing any of your code (well mostly). The default screen is very quick to load on most modern devices, so instead of a splash screen, just use a normal view/view controller for setup.

As both previous answer of #nevan king and #rckoenes, you can present a view controller and have the text or image or whatever in this custom splashscreen.
Add a method on didFinishLaunchingWithOptions to present this view :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Create View Controller
RootViewController *rootViewController = [[RootViewController alloc] init];
// Create Navigation Controller
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
// SplashScreen
[self displaySplashscreen];
return YES;
}
Create displaySplashscreen:
#pragma mark - SplashScreen Methods
- (void)displaySplashscreen
{
// Create View
self.splashscreenViewController = [[SplashscreenViewController alloc] init];
// Display Splashscreen
[_window addSubview:_splashscreenViewController.view];
// Dismiss Splashscreen
[self performSelector:#selector(dismissSplashscreen) withObject:nil afterDelay:3.0f];
}
Create your SplashscreenViewController and build what you need in this view controller.

Related

Add new viewcontroller at launch of app IOS Objective C

I am new to IOS development . i got a open source project and loaded in xcode and it is running good.
the project is based on webview and loading url.
what i want to do is add a new screen at the launch of application which takes three inputs from textfields and on submit of button it should send the data to next screen which is a webview and currently it is being loaded first .
1) how can i add new view controller which launches first at launch of app where i can input textfields and click on button to move to second screen
2) get the data from first screen and give to the load url to load the url.
i have taken project files from here :
https://github.com/paulirish/iOS-WebView-App
viewcontroller option on right side doesnt have the option is initial view
i am using xcode 6.2
I think you are loading viewcontroller from code like we did in older versions. I hope this helps you.
In this code you can simply change MainViewController to your own view.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
MainViewController* viewC =[[MainViewController alloc] initWithNibName:#"MainViewController" bundle:nil];
UINavigationController* navC = [[UINavigationController alloc] initWithRootViewController:viewC];
self.window.rootViewController = navC;
[self.window makeKeyAndVisible];
You will have to create new UIViewController with your three textFields and then set this UIViewController as Initial View Controller from storyboard like this:
After doing this get data from your textfields like:
NSString *text1Data = self.yourtextField.text;//Repeat for all text fields.
After getting data make three variables in your webViewController and assign thse values to them.
Suppose WebVC is yoour WebViewController then you can pass data and go to web viw like this:
WebVC *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"your_WebVc_identifier"];
vc.text1DataFromFirstVC = text1Data; //repeat for all three variables
//go to web view controller
[self.navigationController pushViewController: vc animated:YES]
EDIT:For Non Storyboard use following code from your AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
ViewController *Vc = [[ViewController alloc]initWithNibName:#"ViewController" bundle:nil];
self.window.rootViewController = Vc;
[self.window makeKeyAndVisible];
return YES;
}

iOS 8 - Launching the application in Landscape mode

My iPad application supports all the orientations and it worked fine in iOS 7 as well.
However in iOS 8, launching the application in Landscape mode made my login view draw the landscape view within a portrait frame.
After doing some analysis I found out that the application window does not take the correct orientation while launching in Landscape. Doing a rotation after that corrects the UI since it takes the correct orientation from that point onwards.
Would someone be able to guide me through this? Thanks in advance.
The issue seems to be the order of calls when you set up the window. You need to call makeKeyAndVisible before you assign the rootViewController. The following works:
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
[self.window makeKeyAndVisible];
self.window.rootViewController = self.myMainViewController;
But if you change the order to:
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
self.window.rootViewController = self.myMainViewController;
[self.window makeKeyAndVisible];
You get the behavior you are experiencing.
Thank you Dave Kammeyer for the workaround for this annoying iOS8 bug.
If you are working with storyboards you don't really have access to makeKeyAndVisible because UIApplication automatically wires everything together before calling AppDelegate. In this case, I just reset the rootViewControllerat the start of application:didFinishLaunchingWithOptions:
UIViewController* rootViewController = self.window.rootViewController;
self.window.rootViewController = nil;
self.window.rootViewController = rootViewController;
Afterwards the app starts in landscape without bugs.
I had the root view controller set up in the XIB, by having my navigation controller in the MainWindow.xib, and that navigation ctlr's root view controller the class of my actual root view controller. Thus it would find my root view controller automatically, instantiate it, and hook it op to the navigation controller, and that to the window.
But: apparently that is too early in the game, and causing trouble, when started in landscape mode.
So I broke the Window's connection to the root view controller (being the navigation controller) in the xib, and set the root view controller myself:
self.window.rootViewController = self.navigationController;
Effect is the same as the connection in the nib, but as it happens at a later point it time it is now okay.
The following code worked for me
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
application.statusBarOrientation = UIInterfaceOrientationPortrait;
// the rest of the method
}
Hope it will help !!!

UIWindow's root view controller does not rotate to landscape at app launch

I am developing a xib-based landscape-only app. The app launches in landscape correctly. However, the view in my main ViewController is presented in portrait. That is, it is rotated 90 degrees so that the image appears cropped and does not take up the entire screen. If I use my interface to present a modal view controller then return to the main ViewController, the issue corrects itself (the view is presented in landscape). This problem did not occur under Xcode 4.2. It occurred after upgrading to Xcode 4.3, and the only code changes that were made were automatically implemented by Xcode when I upgraded the project settings.
Based on advice in other posts, I verified my Info.plist settings for Supported Interface Orientations and Initial Interface Orientation. I overrode the shouldAutorotateToInterfaceOrientation method for each of my view controllers to return YES only for landscape orientations. Also, I turned off auto resizing for the view, as I never want the size/orientation of the view to change.
Based on the ideas in this link [1], I suspected the problem is that the view is not receiving the call to change orientation at launch, possibly due to the removal of the MainWindow.xib concept, which appears to be replaced by the following Xcode-inserted code in AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
I modified this method to generate a generic root view controller from which my ViewController class is presented, as shown in the code below:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
ViewController* myViewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil];
self.viewController = [[UIViewController alloc] init];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
[self.viewController presentModalViewController:myViewController animated:NO];
return YES;
}
Voila! This solved my problem. However, to me it feels like a change at a fundamental level, which I don't want to make at this point in my development. What I intended to be my root view controller is now a modal view. Does anyone have another solution to this issue?
Thanks in advance!
I had this same issue: an app which was meant to be in Landscape that assumed the ViewController was always in Portrait. I made tons of changes to every aspect of the project and info.plist, including giving the main UIWindow a root-view controller which was landscape. It still didn't work. I eventually undid all the changes and just added the two lines noted below to my app delegate:
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
[_window addSubview:[_viewController view]];
glView = _viewController.glView;
// THIS FIXED ORIENTATION FOR ME IN IOS 6
_window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
// END
...my other setup code here...
}
Nothing else was necessary.
It appears that, for some reason, in iOS 6 the UIWindow root-view-controller setting is sometimes ignored in Interface Builder. I am sure my reasoning is wrong somewhere, but I thought this might well help prod someone in the direction of a fuller, more exhaustive answer.
In iOS 8, settings windows frame to the UIScreen is also necessary, as it won't get automatically updated.
self.window.frame = [UIScreen mainScreen].bounds;

Hiding the master view in a Split View Controller

I am new to iPad development (or iPhone for that matter :) ) and I am building an app with a Split View Controller.
The thing is the first screen should be a single screen. I want the user to write user/pass data to connect to a remote server, and there's not really anything to show in the master view.
I know I can return YES in the splitViewController:shouldHideViewController:inOrientation:, and that works fine for the first screen, but I'd like to get the two views when the user taps the login button and the credentials are validated.
I can put some condition in shouldHideViewController and that shows the two views in the second screen and only the detail in the first, but shouldHideViewController is only called if I rotate my iPad, not when I perform the segue.
Do you have any tips to do this? Should I change my UI approach to something else? Any suggestions are welcome.
starting from scratch is a good idea. You have more control over whats going on IMO.
At your starting point you want to add your LoginViewController.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.loginController = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
Later when the authentication process has finished you want to continue with SplitView, right?
- (void)continueWithSplitView {
UINavigationController *leftNav = [[UINavigationController alloc] initWithRootViewController:self.masterViewController];
UINavigationController *rightNav = [[UINavigationController alloc] initWithRootViewController:self.detailViewController];
self.splitViewController.viewControllers = [NSArray arrayWithObjects:leftNav, rightNav, nil];
self.view.window.rootViewController = self.splitViewController;
}
Notice that in both methods your desired viewController is set as the rootViewController property of UIWindow. This will automatically add the view of your controller as the top level view in UIWindow.
Furthermore make sure that you are following the MVC pattern e.g. a model object for your credentials organisation.

Change which view opens first (Xcode) [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to change the default View Controller that is loaded when app launches?
So if I made an app and a certain view opens first by default, and decide I want to change which view opens first, how would I do that?
That is controlled in the method in your AppDelegate.m file (or whatever the title of your app delegate file is) called didFinishLaunchingWithOptions. For example, in a tab bar app I've created it looks like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// Add the tab bar controller's current view as a subview of the window
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
return YES;
}
All you have to do is change the value of the self.window.rootViewController. For example, let's say you want a MapViewController to become the first page to open. You could do something like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// Add the tab bar controller's current view as a subview of the window
MapViewController *mvc = [[MapViewController alloc]initWithNibName:#"MapViewController" bundle:nil]; //Allocate the View Controller
self.window.rootViewController = mvc; //Set the view controller
[self.window makeKeyAndVisible];
[mvc release]; //Release the memory
return YES;
}

Resources