0
在我的应用程序我上传图像到服务器。我正在使用这种方法https://stackoverflow.com/a/22301164/1551588。它工作正常,但我想添加进度条到这个方法。有可能的? sendAsynchronousRequest
可以吗?感谢您的回应。上传异步图像进度
在我的应用程序我上传图像到服务器。我正在使用这种方法https://stackoverflow.com/a/22301164/1551588。它工作正常,但我想添加进度条到这个方法。有可能的? sendAsynchronousRequest
可以吗?感谢您的回应。上传异步图像进度
在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];
}
```
你将要上传的图片前,基地64字符串? – Logic