iOS Development--The addition of the Novice guide page

Source: Internet
Author: User

In the past, when the Start page is written, sometimes directly in the startup page, or the VC directly write, but that is not very convenient, the start page will often add a lot of things, so packaged into a separate class, can be used directly, even after the replacement of the later, or other projects need, Directly drag the past, you can directly use very convenient!

The specific code will not be uploaded, with the demo:

Https://github.com/hgl753951/launchTest.git

A demo that was previously uploaded on Cocoachina:

http://code.cocoachina.com/view/131777

Relatively simple, you can download the demo directly to see!

Below is a page with a countdown to the function of the ads:

1, create a new class that is integrated into the UIView:

@interface Hdisplayview:uiview

2,.M file

A, prepare

  @interface   Hdisplayview () {Nsinteger Imgtag    ;    NSString  *PICURL;    Uiimageview  *imageview;    Uiimageview  *SMALLIMG;        UIButton  *TIMERBTN;  int  Secondscountdown; //     countdown total Duration  Nstimer *countdowntimer;}  
@property (Nonatomic,strong) Nsfilemanager **writehandle; @property (nonatomic,assign)Long  long  sumlength; @property (nonatomic,assign)longlong*savedimage ;

b, specifically to achieve

@implementationHdisplayview-(Instancetype) initWithFrame: (cgrect) frame{ Self=[Super Initwithframe:frame]; if(self) {ImageView= [[Uiimageview alloc]initwithframe:cgrectmake (0,0, Mainscreen_width, Mainscreen_height)];//Big background picture                if(Is_iphone4 = =YES) {Imageview.image= [UIImage imagenamed:@"start_ios-1"]; }Else{imageview.image= [UIImage imagenamed:@"Start_ios"]; } imageview.userinteractionenabled=YES;                [Self addsubview:imageview]; Smallimg= [[Uiimageview alloc]initwithframe:cgrectmake (0,0, Mainscreen_width, mainscreen_height-107)];//smallimg.image = [UIImage imagenamed:@ "Start-ad"];[ImageView addsubview:smallimg]; TIMERBTN= [[UIButton alloc]initwithframe:cgrectmake (Mainscreen_width- -- -, -, -, -)];    [Self initview]; }    returnSelf ;}-(void) initbtn{Timerbtn.clipstobounds=YES; TimerBtn.layer.cornerRadius= -; [Timerbtn Settitlecolor:rgb (255,221,0) Forstate:uicontrolstatenormal]; TimerBtn.titleLabel.font= [Uifont systemfontofsize: A];    [Timerbtn addtarget:self Action: @selector (Jumpbtnclick:) forcontrolevents:uicontroleventtouchupinside];    [ImageView ADDSUBVIEW:TIMERBTN]; TimerBtn.titleLabel.numberOfLines=2; TimerBtn.titleLabel.textAlignment=Nstextalignmentcenter; Timerbtn.backgroundcolor= RGBA ( in, in, in,0.5); //start the countdown .Countdowntimer = [Nstimer scheduledtimerwithtimeinterval:1Target:self selector: @selector (Timefiremethod) Userinfo:nil Repeats:yes];//The method is called once per second after the countdown is started Timefiremethod[[Nsrunloop Mainrunloop] Addtimer:countdowntimer Formode:nsdefaultrunloopmode]; //[Nsthread detachnewthreadselector: @selector (Startimer) totarget:self Withobject:nil]; //Set the countdown display time//set the total countdown timeSecondscountdown =5;//60 Seconds Countdown[Timerbtn settitle:[nsstring stringWithFormat:@"Skip \n%ds", Secondscountdown] forstate:uicontrolstatenormal]; //Nstimeinterval period = 1.0;//set the time interval//dispatch_queue_t queue = dispatch_get_global_queue (Dispatch_queue_priority_default, 0);//dispatch_source_t _timer = dispatch_source_create (dispatch_source_type_timer, 0, 0, queue);//Dispatch_source_set_timer (_timer, Dispatch_walltime (NULL, 0), period * nsec_per_sec, 0);//executes per second//Dispatch_source_set_event_handler (_timer, ^{//              //Execute the event here//if (secondscountdown<=0) {//Dispatch_source_cancel (_timer);//Dispatch_async (Dispatch_get_main_queue (), ^{//Self.hidden = YES;//             });////}else{//Dispatch_async (Dispatch_get_main_queue (), ^{//            //if (secondscountdown==0) {//Self.hidden = YES;//}else{//[timerbtn settitle:[nsstring stringwithformat:@ "Skip \n%ds", Secondscountdown] Forstate:uicontrolstate Normal]; //                 }//             });//secondscountdown--;//         }//NSLog (@ "loop execution");//         //[self timefiremethod];//         });//Dispatch_resume (_timer);        }-(void) initview{//first Judgment, 1: If it is the first boot does not display this boot picture, 2: If it is not the first boot, then load this boot picture, if the picture does not exist on the download, if the picture exists on the read cacheHuser *huser =[[Huser alloc]init]; [Hhttpengine getstartuppicrequest:huser success:^(IDresponse) {NSLog (@"respons----%@", response); Nsdictionary*dict = (Nsdictionary *) response; NSString*stautes = [NSString stringWithFormat:@"%@", [Dict Objectforkey:@"Status"]]; if([Stautes isequaltostring:@"1"]) {Picurl= [NSString stringWithFormat:@"%@", [Dict Objectforkey:@"pic"]]; NSLog (@"Picurl is%@", Picurl); [Smallimg sd_setimagewithurl:[nsurl Urlwithstring:picurl] placeholderimage:[uiimage imageNamed:@""]]; Smallimg.userinteractionenabled=YES;        [Self initbtn]; }}failure:^ (Nserror *err) {Self.hidden=YES;    }]; }-(void) Jumpbtnclick: (ID) sender{Self.hidden=YES;}-(void) timefiremethod{//Countdown-1secondscountdown--; //Modify the countdown tag real content[Timerbtn settitle:[nsstring stringWithFormat:@"Skip \n%ds", Secondscountdown] forstate:uicontrolstatenormal]; //when the countdown to 0 o'clock, do the necessary operations, such as verification code expiration cannot be submitted    if(secondscountdown==0) {[Countdowntimer invalidate]; Self.hidden=YES; }}@end

The specific effect is not uploaded, you can directly copy the above code, self-run view effect;

c, adding in Appdelegate, is to add a root view to the current window:

    Hdisplayview *HVC = [[Hdisplayview alloc] Initwithframe:cgrectmake (00, mainscreen_width,  Mainscreen_height)];     = NO;    [Self.window.rootViewController.view ADDSUBVIEW:HVC];    [Self.window BRINGSUBVIEWTOFRONT:HVC];

Done, these two effects can be combined with, judge the first run the app, the Guide page appears, on the contrary, the advertising industry appears!

iOS Development--The addition of the Novice guide page

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.