SAP DEV
SAP DEV

Reputation: 111

iOS: First screen display image

For my phone application, I would like to display an Image in the first screen during 3 secondes and to switch to a main menu without user action.

How can I perform the tempo and switching automatically views ?

Thank you.

Upvotes: 0

Views: 90

Answers (3)

Alessandro Orrù
Alessandro Orrù

Reputation: 3513

I usually do that by creating a view controller that has a UIImageView with the launch image in its view.

Using a modal

You can present it as a modal view controller on top of your rootViewController in this way. In the AppDelegate's application:didFinishLaunchingWithOptions: you present the modal by calling

// rootViewController is the view controller attached to the UIWindow
[rootViewController presentViewController:imageViewController animated:NO completion:nil];

Inside the imageViewController you can do this:

- (void)dismiss {
    // You can animate it or not, depending on your needs
    [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];    
}

- (void)viewDidApper {
    [self performSelector:@selector(dismiss) withObject:nil afterDelay:AMOUNT_OF_TIME];
}

As the first controller of a UINavigationController stack

A similar way that doesn't involve modals is to push this view controller in your UINavigationController (if you use it)

In the AppDelegate's application:didFinishLaunchingWithOptions: you have to set the first controller of the navigation controller with something like this

UINavigationController * navController = [[UINavigationController alloc] initWithRootViewController:imageViewController];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];

Inside the imageViewController you can do this:

- (void)dismiss {
    // Here you should init your nextViewController, the real "home" of the app
    ....

    // Then you can present it. You can animate it or not, depending on your needs.
    // I prefer to replace the whole stack, since user shouldn't go back to the image screen.  
    [self.navigationController setViewControllers:@[nextViewController] animated:YES];    
}

- (void)viewDidApper {
    [self performSelector:@selector(dismiss) withObject:nil afterDelay:AMOUNT_OF_TIME];
}

Upvotes: 0

Anon957
Anon957

Reputation: 560

What you want to do is known as a splash screen, See App Launch (Default) Images Or refer to this guide

Upvotes: 1

arnoapp
arnoapp

Reputation: 2506

Use this

[self performSelector:@selector(loadMainView) withObject:nil afterDelay:3.0];

with the loadMainView method you should begin to setup your usual view

Upvotes: 1

Related Questions