Create boot page [3]

Source: Internet
Author: User

Create boot page [3]

The third method is to write the entire boot page to a controller, which is the most universal way :)

Effect:

Source code:

Appdelegate. m

//// Appdelegate. M // show // copyright (c) 2014 y. x. all rights reserved. // # import "appdelegate. H "# import" welcomeviewcontroller. H "@ implementation appdelegate-(bool) Application :( uiapplication *) Application didfinishlaunchingwitexceptions :( nsdictionary *) launchoptions {self. window = [[uiwindow alloc] initwithframe: [[uiscreen mainscreen] bounds]; // takes over the controller self. window. rootviewcontroller = [welcomeviewcontroller new]; self. window. backgroundcolor = [uicolor whitecolor]; // make the view visible [self. window makekeyandvisible]; return yes;} @ end

Welcomeviewcontroller. m

//// Welcomeviewcontroller. M // show // copyright (c) 2014 y. x. all rights reserved. // # import "welcomeviewcontroller. H "# import" rootviewcontroller. H "@ interface welcomeviewcontroller () @ end @ implementation welcomeviewcontroller-(void) viewdidload {[Super viewdidload];}-(void) viewdidappear :( bool) animated {[self scrollview];} -(void) scrollview {cgrect rect = self. view. window. bounds; cgfloat width = rect. size. width; cgfloat Height = rect. size. height; // initialize scrollview uiscrollview * scrollview = [[uiscrollview alloc] initwithframe: rect]; scrollview. pagingenabled = yes; scrollview. tag = 0x77; scrollview. contentsize = cgsizemake (width * 3, height); // Add some controls for (INT I = 0; I <3; I ++) {uiview * TMP = [[uiview alloc] initwithframe: cgrectmake (I * width, 0, width, height)]; TMP. backgroundcolor = [uicolor colorwithred: arc4random () % 255/255. f green: arc4random () % 255/255. f Blue: arc4random () % 255/255. f ALPHA: 1]; if (I = 2) {yxbutton * button = [[yxbutton alloc] initwithframe: cgrectmake (0, 0,140, 30)]; button. titlelabel. font = [uifont fontwithname: @ "helveticaneue-thin" Size: Hangzhou f]; button. layer. cornerradius = 3.f; [Button addtarget: Self action: @ selector (buttonevent :) forcontrolevents: role]; [Button setbackgroundcolor: [uicolor blackcolor] Priority: [uicolor whitecolor]; [Button setnormaltitlecolor: [uicolor whitecolor] fingerprint: [uicolor blackcolor] disabledtitlecolor: Nil]; [Button setnormaltitle: @ "youxianming" highlightedtitle: @ "youxianming" disabledtitle: @ "youxianming"]; button. center = self. view. window. center; [TMP addsubview: button];} [scrollview addsubview: TMP];} // Add to uiwindow [self. view. window addsubview: scrollview];}-(void) buttonevent :( uibutton *) button {uiscrollview * scrollview = (uiscrollview *) [self. view. window viewwithtag: 0x77]; scrollview. userinteractionenabled = no; // animation [uiview animatewithduration: 2.0 animations: ^ {scrollview. alpha = 0.f;} completion: ^ (bool finished) {// remove this scrollview [scrollview removefromsuperview] From uiwindow; // switch the View Controller self. view. window. rootviewcontroller = [rootviewcontroller new];} @ end

Rootviewcontroller. m

//// Rootviewcontroller. M // show // copyright (c) 2014 y. x. all rights reserved. // # import "rootviewcontroller. H "@ interface rootviewcontroller () @ end @ implementation rootviewcontroller-(void) viewdidload {[Super viewdidload]; self. view. backgroundcolor = [uicolor whitecolor]; [uiview animatewithduration: 2 animations: ^ {self. view. backgroundcolor = [uicolor blackcolor] ;}] ;}@ end

Notes:

Switch the View Controller after the animation ends.

More natural transition

 

Summary:

The core of the boot pages created in these tutorials is to load the view or View Controller on the uiwindow, which is so easy :)

 

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.