The app launches the boot interface and launch interface settings for the first time--ios development

Source: Internet
Author: User

App download installation for the first time, it will usually show a first boot interface and then go to the main interface, not the first time the app will also display a splash screen and then go to the main interface.

1. This example starts the display Firstuseviewcontroller for the first time, adds a button, clicks into Launchviewcontroller
2, non-first launchviewcontroller, display 2s backward master interface Viewcontroller
3. Main interface Viewcontroller
4, do not delve into the details, the general start-up guide will have animation, pictures and the like, not the focus of this exercise, so there is no setting, only simple logo for the interface to distinguish
(at the end of the article)

Firstuseviewcontroller.m

- (void) Viewdidload {[SuperViewdidload]; Self. View. BackgroundColor= [UicolorGreencolor];UIButton*button = [[UIButtonAlloc] Initwithframe:cgrectmake (0,0, -, -)]; button. Center= Self. View. Center; [Button settitle:@"Welcome"Forstate:uicontrolstatenormal]; [Button AddTarget: SelfAction@selector(btnaction:) forcontrolevents:uicontroleventtouchupinside]; [ Self. ViewAddsubview:button];}//Click button to switch to the next interface- (void) Btnaction: (UIButton*) btn {Launchviewcontroller *VC = [[Launchviewcontroller alloc] init]; Self. View. Window. Rootviewcontroller= VC;}

Launchviewcontroller.m

- (void) Viewdidload {[SuperViewdidload]; Self. View. BackgroundColor= [UicolorBluecolor];UILabel*label = [[UILabelAlloc] Initwithframe:cgrectmake (0,0, $, -)]; Label. Center= Self. View. Center; [Label setfont:[UifontSystemfontofsize: -]]; Label. Text= @"Start Page"; [ Self. ViewAddsubview:label];//delay 2s call, General start page will stay, or some animation what, this example only briefly outline the idea, do not delve into the details[ SelfPerformselector:@selector(ChangeView) Withobject: SelfAfterdelay:2];additional setup after loading the view.}//Switch to the next interface- (void) ChangeView {UIWindow*window = Self. View. Window; Viewcontroller *main = [[Viewcontroller alloc] init];//Add a zoom effectMain. View. Transform= Cgaffinetransformmakescale (0.2,0.2); [UIViewAnimatewithduration:0.1animations:^{Main. View. Transform= Cgaffinetransformidentity;    }]; Window. Rootviewcontroller= Main;}

Viewcontroller.m

- (void)viewDidLoad {    [super viewDidLoad];    self.view.backgroundColor = [UIColor grayColor];    [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 50)];    label.center = self.view.center;    [label setFont:[UIFont systemFontOfSize:30]];    label.text = @"主界面";    [self.view addSubview:label];}

The APPDELEGATE.M is set in two ways. Personally feel that the second use of nsuserdefaults to achieve more convenient

- (BOOL) Application: (uiapplication*) Application Didfinishlaunchingwithoptions: (nsdictionary*) Launchoptions { Self. Window= [[UIWindowAlloc] Initwithframe:[uiscreen Mainscreen]. Bounds]; Self. Window. BackgroundColor= [UicolorWhitecolor]; [ Self. WindowMakekeyandvisible];////Use file operations to determine if you are using this app for the first time//NSString *filepath = [Nshomedirectory () stringbyappendingpathcomponent:@ "Documents/firstuse.plist"]; The first boot, without this file, is automatically created//Nsdictionary *dic = [Nsdictionary Dictionarywithcontentsoffile:filepath];//    //BOOL notfirstuse = YES;//Notfirstuse = [dic[@ "Notfirstuse"] boolvalue];//if (!notfirstuse) {//Nsdictionary *dic = @{@ "Notfirstuse": @YES};//[dic Writetofile:filepath Atomically:yes];//Firstuseviewcontroller *VC = [[Firstuseviewcontroller alloc] init];//Self.window.rootViewController = VC;//}else {//Launchviewcontroller *VC = [[Launchviewcontroller alloc] init];//Self.window.rootViewController = VC;//    }////using Nsuserdefaults to achieve    if(! [[NsuserdefaultsStandarduserdefaults] boolforkey:@"Firstlaunch"]) {        [[NsuserdefaultsStandarduserdefaults] Setbool:YESforkey:@"Firstlaunch"];NSLog(@"first start"); Firstuseviewcontroller *VC = [[Firstuseviewcontroller alloc] init]; Self. Window. Rootviewcontroller= VC; }Else{NSLog(@"Non-first boot"); Launchviewcontroller *VC = [[Launchviewcontroller alloc] init]; Self. Window. Rootviewcontroller= VC; }return YES;}

Interface:
First launch page:

Non-first start page:

Main interface:

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The app launches the boot interface and launch interface settings for the first time--ios development

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.