iOS development first launch show user boot, second boot directly into app

Source: Internet
Author: User

First, create a controller class for the bootstrap diagram.

UserGuideViewController.h and USERGUIDEVIEWCONTROLLER.M
#import <UIKit/UIKit.h>#import"firstViewController.h"# Define WIDTH self.view.frame.size.width#define HEIGHT self.view.frame.size.height@interface userguideviewcontroller:uiviewcontroller<uiscrollviewdelegate>@end
#import "UserGuideViewController.h"@interfaceUserguideviewcontroller () @property (strong,nonatomic) Uiscrollview*ScrollView, @property (strong,nonatomic) Uipagecontrol*page; @property (strong,nonatomic) Uiimageview*Image1, @property (strong,nonatomic) Uiimageview*Image2, @property (strong,nonatomic) Uiimageview*Image3, @property (strong,nonatomic) UIButton*btn;@end@implementationUserguideviewcontroller- (void) viewdidload {[Super viewdidload]; //Load User Guide diagram[self initscroll];}-(void) initscroll{Self.image1=[[uiimageview Alloc]initwithframe:cgrectmake (0,0, WIDTH, HEIGHT)]; Self.image1.image=[uiimage imagenamed:@"1"]; Self.image2=[[uiimageview Alloc]initwithframe:cgrectmake (WIDTH,0, WIDTH, HEIGHT)]; Self.image2.image=[uiimage imagenamed:@"2"]; Self.image3=[[uiimageview Alloc]initwithframe:cgrectmake (width*2,0, WIDTH, HEIGHT)]; Self.image3.image=[uiimage imagenamed:@"3"]; Self.scrollview=[[Uiscrollview alloc]initwithframe:self.view.frame]; Self.scrollView.backgroundColor=[Uicolor Redcolor]; Self.scrollView.contentSize=cgsizemake (width*3, HEIGHT); //Lock Scroll DirectionSelf.scrollview.directionallockenabled=YES; //Set Page PagingSelf.scrollview.pagingenabled=YES; //Hide scroll barSelf.scrollview.showshorizontalscrollindicator=NO; //set whether to reboundself.scrollview.bounces=NO; //Add buttonSelf.btn=[[uibutton Alloc]initwithframe:cgrectmake ( the, -, the,Panax Notoginseng)]; [Self.btn settitle:@"Experience Now"Forstate:0]; Self.btn.titleLabel.font=[uifont boldsystemfontofsize: -]; [Self.btn settitlecolor:[uicolor colorwithred:1.000Green0.886Blue0.107Alpha1.000] Forstate:0]; Self.btn.backgroundColor=[Uicolor Redcolor];    [Self.btn addtarget:self Action: @selector (firstpressed) forcontrolevents:uicontroleventtouchupinside];        [Self.image3 ADDSUBVIEW:SELF.BTN]; //To set pagination individual propertiesSelf.page=[[Uipagecontrol alloc]init]; Cgsize pageSize=cgsizemake ( -, -); Self.page.frame=cgrectmake ((width-pagesize.width) *0.5, height-pagesize.height- +, Pagesize.width, pagesize.height); Self.page.backgroundColor=[Uicolor Clearcolor]; //Set Paging page Countself.page.numberofpages=3; Self.page.currentPage=0; Self.scrollview.Delegate=Self ;    [Self.scrollview AddSubview:self.image1];    [Self.scrollview AddSubview:self.image2];        [Self.scrollview AddSubview:self.image3];    [Self.view AddSubview:self.scrollView];    [Self.view AddSubview:self.page]; //Open User interaction, or the following button cannot respondSelf.image3.userinteractionenabled=YES;}//The penalty time of the button-(void) firstpressed{//Skip to Text[Self Presentviewcontroller:[firstviewcontrollerNew] Animated:yes completion:^{            }];}-(void) Scrollviewdidscroll: (Uiscrollview *) scrollview{//Set Page PagingSelf.page.currentPage=(int) (scrollview.contentoffset.x/WIDTH);}- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}/*#pragma mark-navigation//in a storyboard-based application, you'll often want to do a little preparation before n avigation-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) Sender {//Get the new view controller using [s]    Egue Destinationviewcontroller]. Pass the selected object to the new view controller.}*/@end

Body page FirstViewController.h and FIRSTVIEWCONTROLLER.M

#import <UIKit/UIKit.h>@interface  firstviewcontroller:uiviewcontroller@end 
#import "FirstViewController.h"@interfaceFirstviewcontroller ()@end@implementationFirstviewcontroller- (void) viewdidload {[Super viewdidload]; Self.view.backgroundColor=[Uicolor Redcolor];}- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}/*#pragma mark-navigation//in a storyboard-based application, you'll often want to do a little preparation before n avigation-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) Sender {//Get the new view controller using [s]    Egue Destinationviewcontroller]. Pass the selected object to the new view controller.}*/@end

Appdelegate.mappdelegate.h file

#import <UIKit/UIKit.h>#import"firstViewController.h"# Import"UserGuideViewController.h"@interface appdelegate:uiresponder <UIApplicationDelegate>*window; @end
#import "AppDelegate.h"@interfaceappdelegate ()@end@implementationappdelegate-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {SELF.FIRSTVC=[[Firstviewcontroller alloc]init]; //determine if the application is the first time to start    if(! [[Nsuserdefaults Standarduserdefaults] Boolforkey:@"Firstlaunch"]) {[[Nsuserdefaults standarduserdefaults]setbool:yes Forkey:@"Firstlaunch"]; NSLog (@"first time start"); //If this is the first time, use Userguideviewcontroller (User Guide page) as the root viewUserguideviewcontroller *userviewcontroller=[[Userguideviewcontroller alloc]init]; Self.window.rootViewController=Userviewcontroller; }Else{NSLog (@"not the first time ."); //use first as the root view if it is not the initial startFirstviewcontroller *first=[[Firstviewcontroller alloc]init]; Self.window.rootViewController=First ; } Self.window.backgroundColor=[Uicolor Whitecolor];                [Self.window makekeyandvisible]; returnYES;}- (void) Applicationwillresignactive: (UIApplication *) Application {//Sent when the application are about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as a incoming phone call or SMS message) or when the US    Er quits the application and it begins the transition to the background state. //Use the This method to the pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.}- (void) Applicationdidenterbackground: (UIApplication *) Application {//Use the method to release the shared resources, save user data, invalidate timers, and store enough application state in    Formation to the restore your application to the it is terminated later. //If Your application supports background execution, this method is called instead of Applicationwillterminate:when th E user quits.}- (void) Applicationwillenterforeground: (UIApplication *) Application {//Called as part of the transition from the background to the inactive state; Here you can undo many of the changes mad E on entering the background.}- (void) Applicationdidbecomeactive: (UIApplication *) Application {//Restart Any tasks this were paused (or not yet started) while the application is inactive. If the application is previously in the background, optionally refresh the user interface.}- (void) Applicationwillterminate: (UIApplication *) Application {//Called when the application are about to terminate. Save data if appropriate. See also Applicationdidenterbackground:.}@end

Run effect

Run for the first time

Second run

iOS development first launch show user boot, second boot directly into app

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.