回答

1

在iOS中看起来无法获得进度值。

但是,我发现了一个很好的解决方法,他基本上是作弊,但在视觉上,他做了这项工作。

你给自己填上进度指示器,最后确保它已满。

原来的答案UIWebView with Progress Bar

与改进的代码:你需要

[self startProgressView]; 

然后

第一次调用(显然):

#pragma mark - Progress View 

Boolean finish = false; 
NSTimer *myTimer; 

-(void)startProgressView{ 
    _progressView.hidden = false; 
    _progressView.progress = 0; 
    finish = 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)stopProgressView { 
    finish = true; 
    _progressView.hidden = true; 
} 

-(void)timerCallback { 
    if (finish) { 
     if (_progressView.progress >= 1) { 
      _progressView.hidden = true; 
      [myTimer invalidate]; 
     } 
     else { 
      _progressView.progress += 0.1; 
     } 
    } 
    else { 
     _progressView.progress += 0.00125; 
     if (_progressView.progress >= 0.95) { 
      _progressView.progress = 0.95; 
     } 
    } 
    //NSLog(@"p %f",_progressView.progress); 
} 

这里如何使用它在代表

#pragma mark - NSURLConnection Delegate Methods 

- (void)connectionDidFinishLoading:(NSURLConnection *)connection { 
    NSLog(@"Loaded"); 
    [self stopProgressView]; 
} 

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { 
    NSLog(@"Error %@", [error description]); 
    [self stopProgressView]; 
} 

```