How to Create a startup interface for an Iphone application

Source: Internet
Author: User

This tutorial describes how to create a startup interface for an Iphone application.

Create a project in Xcode and use the "Single View Application" template to name it Splash. Do not use storyboard or ARC.

Select "ViewController. in the "xib" file, the background color of the View is changed to white. Run the project with Command + Run. After the program starts, you will first see a black interface, followed by a white interface.

Download the following image and import it to your project. Change it to default.png.

 


 

When you run your project again, you will find that this picture is the startup interface of your program. Yes, it's easy to torture. If you have enough curiosity, I will tell you the mechanism behind this: the system will show users some pictures of the image file named default.png before your program code is fully loaded. If you do not provide this file, it will not display anything. In fact, this is not true. It will show Black-when there is no light, it will become black.
The above startup interface is displayed and the application homepage is directly displayed. The display time of the startup interface is not controlled by us. Programmers have a strong desire for code control. Haha, for example, we want to start the interface to display 2 ~ 3 seconds later, go to the application homepage to provide the loading time for our application. How can this requirement be met?
The basic idea is to place the startup interface image in a mode view. The mode view is displayed immediately after the application is started. after a certain period of time, the mode view disappears. Let's get started.
Step 1: Upload File.
Step 2: Create an IBOutlet attribute in the ViewController. m file and name it modalView. link it to the UIView object created in the previous step.
Step 3: Add two methods to the ViewController class: showSplash and hideSplash. The Code is as follows:
1.-(void) showSplash {
2. UIViewController * modalViewController = [[UIViewController alloc] init];
3. modalViewController. view = self. modalView;
4. [self presentModalViewController: modalViewController animated: NO];
5. [modalViewController release];
6.
7. // Dismiss the modalView after 3 seconds.
8. [self defined mselector: @ selector (hideSplash) withObject: nil afterDelay: 3.0f];
9 .}
10.-(void) hideSplash {
11. [self dismissModalViewControllerAnimated: NO];
12 .}
 
 
The code is still very simple. If you do not understand it, you can check the document.
Step 4: In the-application: didfinishlaunchingwitexceptions: Method in the AppDelegate. m file, add the following sentence before return:
1. // Continue showing the splash image.
2. [self. viewController showSplash];
This is to continue displaying the startup interface immediately when the program enters the home page. After the application is started, the system uses the default.png file as the startup interface. After the application is started, the system displays the startup interface for three seconds and then enters the application's first interface. If you want to keep displaying the startup interface and dismiss an event, you can create a wait loop in the showSplash method, when an expected event occurs, for example, after data is loaded, you call the hideSplash method to dismiss the startup interface view.
The only thing to note is that the Default.png size is 320*480. By default, the Iphone application displays the status bar with a height of 20 points. Therefore, when building a modalView in Interface Builder, note that UIImageView must be shifted to 20 point. For details, refer to the size settings of the object in IB.
See Attachment: http://www.bkjia.com/uploadfile/2012/0522/20120522023032344.zip for the source code of this tutorial
 

 

 

From the deep-learning experience

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.