IOS Development Study Notes-(3) progress bar, waiting for the animation to stop
1. Create a spatial view, for example:
2. Compile the corresponding. h Code as follows:
#import
@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
3. Compile the implementation of the corresponding. m file. The notes are more detailed:
# Import ViewController. h @ interface ViewController () @ end @ implementation ViewController @ synthesize activWaitNetWork; @ synthesize pgrsDownLoad; @ synthesize timer;-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib .} -(IBAction) onclickStartRequest :( id) sender {// if it is running, stop; otherwise, start to load if ([activWaitNetWork isAnimating]) {[activWaitNetWork stopAnimating];} else {[activWaitNetWork startAnimating] ;}}-(IBAction) onclickDownLoad :( id) sender {// start the progress pgrsDownLoad again. progress = 0; // The progress of the scheduled task and the new Progerss timer = [NSTimer scheduledTimerWithTimeInterval: 1.0 target: self selector: @ selector (update) userInfo: nil repeats: YES];} -(void) update {pgrsDownLoad. progress = pgrsDownLoad. SS + 0.1; // when the progress is complete, the system prompts if (pgrsDownLoad. progress = 1) {[timer invalidate]; UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ tip message: @ delegate: self cancelButtonTitle: @ confirm otherButtonTitles: @ cancel, nil]; [alert show] ;}}-(void) didReceiveMemoryWarning {[super didreceivemorywarning]; // Dispose of any resources that can be recreated .} @ end
Iv. Running effect: