UIWebView with progress

 //progress@property (strong, nonatomic) UIProgressView *progressView;

//timer to fresh progress
@property (nonatomic,strong) NSTimer *myTimer;
//sign web load status
@property (nonatomic,assign) BOOL theBool;

//when web start load initialization
- (void)webViewDidStartLoad:(UIWebView *)webView{
     progressView.hidden = NO;
   myProgressView.progress = 0;
     theBool = false;
     //0.01667 is roughly 1/60, so it will update at 60 FPS
     myTimer = [NSTimer scheduledTimerWithTimeInterval:0.01667 target:self selector:@selector(timerCallback) userInfo:nil repeats:YES];
}
//when web load successfully , progress view hide
- (void)webViewDidFinishLoad:(UIWebView *)webView{
     theBool = true;
}
//fresh progress view
-(void)timerCallback {
    if (theBool) {
         if (myProgressView.progress >= 1) {
              myProgressView.hidden = true;
              [myTimer invalidate];
         }
         else {
              myProgressView.progress += 0.1;
         }
    }
    else {
         myProgressView.progress += 0.05;
         if (myProgressView.progress >= 0.95) {
              myProgressView.progress = 0.95;
         }
    }
}

 

posted @ 2016-03-25 12:03  optt  阅读(297)  评论(0编辑  收藏  举报