こんにちは私はプログラミングに不慣れで、XcodeでiPhone用の最初のアプリを作ろうとしています。私のアプリには、押されたときにUIWebViewを開き、ホームページをロードするボタンが含まれています。ここで、Safariも使用するように、進行状況ビューをWebViewに追加します。これは、ページの読み込みの進行状況を示します。どうやってやるの?
UIWebViewにURLをロードするためのこれまでの私のコード:
.h
IBOutlet UIWebView *webView;
.m
- (void)viewDidLoad
{
[webView loadRequest:[NSURLRequest requestWithURL: [NSURL URLWithString:@"http:/www.google.com/"]]];
ご協力いただきありがとうございます!
正確UIProgressView
にするには、次のようなタスクが必要です。
今、あなたがあなたをロードしているとき、それはUIWebView
不可能です。そしてAppleもそれをしません。Appleはしばしば偽物を使用UIProgressView
して、ページの読み込み中に何かを見ることができます。メールも偽の進行状況ビューを使用します。ぜひお試しください。これは、Appleの偽の進捗ビューがどのように機能するかです。
これを実現するには、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ステートメントの値を変更して、アニメーションの速度を制御します。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加