如何在UIWebView中添加Progress View

时间:2016-11-06 08:56:16

标签: ios objective-c xcode uiwebview progress-bar

ViewController.m

- (void)viewDidLoad {
    self.webViewIpad.scalesPageToFit = YES;
    NSString *urlString = @"https://google.com";
    NSURL *url = [NSURL URLWithString:urlString];
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
   [self.webViewIpad loadRequest:urlRequest];
}

- (void)webViewDidStartLoad:(UIWebView *)webView {
    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];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    theBool = true;`
}

- (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;
        }
    }
}

我的代码中有这个。 如何在进度条中连接我的网页视图? 任何人都可以帮助我吗?

0 个答案:

没有答案