"IOS" mimics the "new hot List of drawers" Dynamic Start Page Yfsplashscreen

Source: Internet
Author: User

iOS is best to set the system default boot page, or the app will suddenly flash black screen

Is the effect we want to achieve:

General idea : set a system default boot page, in the Enter when Didfinishlaunchingwithoptions,

Add a Custom Launch page to window, with the same splash screen as the system startup page.

Some animations can be implemented on the custom launch page, and after the animation finishes, the custom launch page is removed.

I. Setting the system default startup page

The new project will now automatically generate the Launchscreen.storyboard startup paging file.

Come to the project root and click General to find the following:

Discover that in addition to setting launch screen File directly, you can also set launch Image source to implement the Add Launch page.

So let's use this approach to achieve it. Use assets.xcassets to add pictures,

1.launchscreen.storyboard We can't use it, we can delete it. At the same time, the third row launch screen file is set to NULL.

2. Second line, click User Asset Cattalog, Migrate: This time luanch Images source will become Brand Assets

But that's not what we need. So, click on the arrow on the right, go to assets.xcassets, right in AppIcon, select

APP icons&launch images->new IOS Launch Images, there are plenty of boxes to fill in the picture on the right.

The second row is then returned with the Luanchimage selected, and the result is as shown in the following settings.

Now add a picture to the newly created Launchimage to show the system's default splash screen.

Many tutorials on the web are over, how to add pictures but don't know. How to set the picture please look down.

(The result is that when the image is added, there are big black edges on the top and bottom, or no picture shows)

Two. Set the system boot page picture

The contents of the Launchimage are as follows, and I have already labeled the corresponding image resolution.

(in order to adapt to different size of the screen, in addition to landscape horizontal screen, a total of five different resolutions of the figure, has been color-coded)

Then the different size of the device used by the picture (this name is just for better correspondence, the picture into the launchimage corresponding position)

The logical coordinate system (resolution) size here can be understood as getting to the [UIScreen mainscreen].bounds.size size.

Therefore, the above 5 resolution picture corresponding to put in, you can achieve the normal system default startup page.

(Note: Do not add these to the project, drag directly to the corresponding location of the launchimage, in the directory

Assets.xcassets/launchimage.launchimage you can see automatically generated images of a specific name, total 7 photos)

Three. customizing page UIView

1. Setting the background

After the system default splash screen is finished, the custom UIView we added to the window is displayed.

For the smoothness of the picture, the background still needs to be set to the same image as the start screen.

For different devices, the system default splash screen will show a different picture, if we manually to determine the assignment UIView background, it is a bit troublesome.

We can get the launchimage currently in use through the Infodictionary "Uilaunchimages" in NSBundle.

The above obtained is a dictionary array dicarrays, and its number will be changed as you add the Launchimage picture.

Here I list the dicarays that was acquired when all screens (Dicarrays number 4) were fitted. The following table:

So we just have to go through the uilanuchimagename of the corresponding size and direction.

-(NSString *) Getcurrentlaunchimagenamefororientation: (uiinterfaceorientation) orientation{nsstring*currentimagename =Nil; Cgsize viewsize=self.bounds.size; NSString* Vieworientation =@"Portrait"; if(Uiinterfaceorientationislandscape (orientation)) {Viewsize=Cgsizemake (Viewsize.height, viewsize.width); Vieworientation=@"Landscape"; } Nsarray*imagedicts = [[[NSBundle Mainbundle] infodictionary] Valueforkey:@"uilaunchimages"];  for(Nsdictionary * DICinchimagedicts) {cgsize imageSize= Cgsizefromstring (dic[@"uilaunchimagesize"]);        //Convert string to size NSString*orientation = dic[@"uilaunchimageorientation"]; //Get directions if(Cgsizeequaltosize (Viewsize, imageSize) &&[Orientation isequaltostring:vieworientation]) {Currentimagename= dic[@"Uilaunchimagename"]; }    }        returnCurrentimagename;}

Once you get the name, you can assign a value to uiimage directly from that name.

2. Setting the icon and name

Have you noticed that the icon and text of the "Drawer new hot List" are always there, then the background color changes to other pictures.

My idea is to cover the top of the list with the icon and text of the new hot drawer . The structure of the view after the system default boot diagram is complete.

(red circle, from left to right is the top layer of the picture + text, to animate the Uiimageview, UIView itself background image)

As a uiview, we need to add icons and text that are exactly the same as the background image at the top of the default, to ensure that the launchimage jumps from the system to the custom page, where the content will not change. However, the splash screen is available in several sizes, so you need to add the icon to the UIView at a certain scale. So it is better to start the screen with a certain proportion of the internal icon, text design.

But because there is no art, I think of a way. Directly to the icon, text, the background according to a certain proportion of the layout to UIView, and then to the different simulator.

(My layout: square icon width, height is the screen width of the 1/6 icon y value for screen height 1/7)

On the 4, 4.7, 5, 5.5-inch simulators, you can get the desired proportions after switching to the maximum window (command+1) (command+s)

On the 3.5-inch simulator, command+ 1 is: 640 * 960 COMMAND+3:320*480

This will not only get the start-up picture, you also have the top-level picture and text layout.

3. Network Request and Sandbox save

Now the overall is done, there is a function, is within the client can replace the network image, the next time you re-enter the application to take effect.

So involves the network request nsurlsession and sandbox, here omit and make some records.

Use related objects such as Taskdownloadsession

A. If the block is implemented, the protocol cannot be entered, and the delegate protocol can be used to restore the download, real-time progress and other control.

B. totalbytesexpectedtowrite-1 solution in the Protocol for Progress Control:

Nsmutableurlrequest *request;

[Request setvalue:@ "" forhttpheaderfield:@ "accept-encoding"];

See Stackoverflow:mbprogresshud with Nsurlconnection

The source code and instructions are detailed on GitHub: Yfsplashscreen

"IOS" mimics the "new hot List of drawers" Dynamic Start Page Yfsplashscreen

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.