iOS development first boot show user boot, second boot directly into App,uiscrollview,uipagecontrol,nsuserdefaults

Source: Internet
Author: User
Tags uikit

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" @interface Userguideviewcontroller () @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 @implementation userguideviewcontroller-(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 direction self.scrollview.directionallockenabled=yes;    Set paging Self.scrollview.pagingenabled=yes;    Hide scroll bar self.scrollview.showshorizontalscrollindicator=no;        Set whether to rebound self.scrollview.bounces=no;        Add button Self.btn=[[uibutton alloc]initwithframe:cgrectmake (80, 600, 230, 37)];    [Self.btn settitle:@ "experience immediately" forstate:0];    Self.btn.titlelabel.font=[uifont BOLDSYSTEMFONTOFSIZE:20];    [Self.btn settitlecolor:[uicolor colorwithred:1.000 green:0.886 blue:0.107 alpha:1.000] forState:0];    Self.btn.backgroundcolor=[uicolor Redcolor];    [Self.btn addtarget:self Action: @selector (firstpressed) forcontrolevents:uicontroleventtouchupinside];        [Self.image3 ADDSUBVIEW:SELF.BTN];    Set pagination properties Self.page=[[uipagecontrol Alloc]init];    Cgsize Pagesize=cgsizemake (120, 44); Self.page.frame=cgrectmake (width-pagesize.width) *0.5, height-pagesize.height-40, PageSIze.width, Pagesize.height);    Self.page.backgroundcolor=[uicolor Clearcolor];    Set paging page self.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, otherwise the button below cannot respond to self.image3.userinteractionenabled=yes;} Button penalty time-(void) firstpressed{//jump to text [self presentviewcontroller:[firstviewcontroller new] Animated:yes complet ion:^{}];} -(void) Scrollviewdidscroll: (Uiscrollview *) scrollview{//Set paging self.page.currentpage= (int) (scrollview.contentoffs Et.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 navigation-(void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) Sender {//Get the new View Co    Ntroller using [Segue 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" @interface Firstviewcontroller () @end @implementation firstviewcontroller-(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 Nav igation-(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> @property (strong,nonatomic) Firstviewcontroller *firstvc;@ Property (Strong, Nonatomic) UIWindow *window; @end
#import "AppDelegate.h" @interface appdelegate () @end @implementation appdelegate-(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:y        ES forkey:@ "Firstlaunch"];        NSLog (@ "first start"); If this is the first time, use Userguideviewcontroller (User Guide page) as the root view Userguideviewcontroller *userviewcontroller=[[        Userguideviewcontroller Alloc]init];    Self.window.rootviewcontroller=userviewcontroller;        }else{NSLog (@ "is not the first time to start");        Use first as the root view Firstviewcontroller *first=[[firstviewcontroller Alloc]init] If it is not the initial start;            Self.window.rootviewcontroller=first;    } Self.window.backgroundcolor=[uicolor Whitecolor];                [Self.window makekeyandvisible]; return YES;} -(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 with this method to pause the game.} -(void) Applicationdidenterbackground: (uiapplication *) application {//Use the method to release shared resources, SA  ve user data, invalidate timers, and store enough application state information to restore your application    State-in-case it is terminated later. If your application supports background execution, this method is called instead of Applicationwillterminate:when the User quits.} -(void) Applicationwillenterforeground: (uiapplication *) application {//called as part of the transition from THe background to the inactive state; Here's can undo many of the changes made on entering the background.} -(void) Applicationdidbecomeactive: (uiapplication *) application {//Restart any tasks this were paused (or not yet STA rted) While the application was inactive. If the application is previously in the background, optionally refresh the user interface.} -(void) Applicationwillterminate: (uiapplication *) application {//called when the application was about to terminate. S Ave data if appropriate. See also Applicationdidenterbackground:.} @end

Run effect

Run for the first time

Second run

iOS development first boot show user boot, second boot directly into App,uiscrollview,uipagecontrol,nsuserdefaults

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.