有一个准确的UIProgressView
,你需要有一些任务:
- 您可以从获取信息,而这是不完整的
- 量化它的“完整性”基于这些信息的百分比。
现在当你加载你的UIWebView
,那是不可能的。而苹果也没有这样做。在加载页面时,Apple经常使用假冒UIProgressView
s给你一些东西。邮件也使用虚假的进度视图。去自己尝试一下。这就是苹果的假进度的看法工作:
- 的发展观开始以缓慢,恒定速率
- 移动如果条完成前的任务完成后,它突然越过其余拉链100%消失
前
- 如果任务需要很长时间,则进度视图将停止在95%,并且会一直保持到任务完成。
要做到这一点,你必须手动动画progressView。你可以对它进行子类化,但这可能会对你有所帮助。最简单的方法是这样的:
在myViewController.h
@interface myViewController : UIViewController {
BOOL theBool;
//IBOutlet means you can place the progressView in Interface Builder and connect it to your code
IBOutlet UIProgressView* myProgressView;
NSTimer *myTimer;
}
@end
在myViewController.m
#import "myViewController.h"
@implementation myViewController
- (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;
}
}
}
@end
然后,在你的任务完成后得到,设置theBool = true;
和进度视图会照顾本身。更改if语句中的值以控制动画的速度。
查看这里的答案,以获得更好的解决方案,了解放置进度条代码的位置http://stackoverflow.com/questions/23966697/show-progress-bar-until-it-load-the-data -in-uiwebview-ios7 – Suhaib