Webview在Xcode中加载微调器

时间:2010-01-21 04:26:37

标签: cocoa webkit nsprogressindicator

我正在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];
}

1 个答案:

答案 0 :(得分:2)

Be the frame load delegatestop the progress indicator's animation,当主框架完成加载时。

仅当您收到did-finish-load消息的帧是Web视图的主框架时才停止动画。您将在Web视图中为每个帧获取其中一条消息,包括嵌套帧和iframe。你不想过早地停止动画。