2

我正在 Webview 中加载远程 URL,并且我想在加载内容时显示一个微调器。我有以下代码,但是当内容完成加载时微调器不会消失。如何使微调器在加载内容后消失?

NSURL *noteURL = [NSURL URLWithString:@"http://google.com/"];
NSString *defaultNote = @"Hello there";

NSRect frame = [[noteView superview] frame];
noteSpinner = [[[NSProgressIndicator alloc] initWithFrame:NSMakeRect(NSMidX(frame)-16, NSMidY(frame)-16, 32, 32)] autorelease];
[noteSpinner setStyle:NSProgressIndicatorSpinningStyle];
[noteSpinner startAnimation:self];
//webViewFinishedLoading = NO;
[[noteView superview] addSubview:noteSpinner];

if (noteURL)
{
    if ([noteURL isFileURL])
    {
        [[noteView mainFrame] loadHTMLString:@"Release notes with file:// URLs are not supported for security reasons—Javascript would be able to read files on your file system." baseURL:nil];
    }
    else
    {
        [[noteView mainFrame] loadRequest:[NSURLRequest requestWithURL:noteURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30]];
    }
}
else
{
    [[noteView mainFrame] loadHTMLString:defaultNote baseURL:nil];
}
4

1 回答 1

2

成为框架加载委托,并在主框架完成加载时停止进度指示器的动画。

仅当您收到完成加载消息的帧是 Web 视图的主帧时才停止动画。您将在 Web 视图中的每个框架(包括嵌套框架和 iframe)中获得其中一条消息。您不想过早停止动画。

于 2010-01-21T05:10:21.557 回答