iOS Development Learning notes-(3) Progress bar, wait for animation to start to stop

Source: Internet
Author: User

First, create a corresponding spatial view, such as:


Second, write the corresponding. h code, as follows:

#import <UIKit/UIKit.h> @interface viewcontroller:uiviewcontroller@property (weak, nonatomic) Iboutlet Uiactivityindicatorview *activwaitnetwork; @property (weak, nonatomic) Iboutlet Uiprogressview *pgrsdownload;@ Property (weak,nonatomic) Nstimer *timer;-(ibaction) Onclickstartrequest: (ID) sender;-(ibaction) Onclickdownload: (ID ) Sender; @end


Third, write the implementation of the corresponding. m file, and comment more detailed:


#import "ViewController.h" @interface Viewcontroller () @end @implementation viewcontroller@synthesize activwaitnetwork; @synthesize pgrsdownload; @synthesize timer;-(void) viewdidload{[super viewdidload];//do any additio NAL Setup after loading the view, typically from a nib.} -(Ibaction) Onclickstartrequest: (ID) sender{//If it is running, stop or start running load if ([Activwaitnetwork isanimating]) {[    Activwaitnetwork stopanimating];    }else{[Activwaitnetwork startanimating];        }}-(ibaction) Onclickdownload: (ID) sender{//Restart Progress pgrsdownload.progress = 0; Timing task with new Progerss Progress timer = [Nstimer scheduledtimerwithtimeinterval:1.0 target:self selector: @selector (update) Useri    Nfo:nil Repeats:yes];    }-(void) update{pgrsdownload.progress = pgrsdownload.progress + 0.1;                When progress is complete, prompt to download complete if (pgrsdownload.progress = = 1) {[Timer invalidate]; Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "Warm tip" message:@ "File Download Complete" Delegate:selfcancelbuttontitle:@ "OK" otherbuttontitles:@ "Cancel", nil];    [Alert show];    }}-(void) didreceivememorywarning{[Super didreceivememorywarning]; Dispose of any resources the can be recreated.} @end

Four, the operation effect, as follows:



Code Address: http://download.csdn.net/detail/jiangtao_st/7684965


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.