Xcode 中的 Webview 加载微调器

发布于 2024-08-18 18:57:36 字数 1063 浏览 5 评论 0原文

我正在 Web 视图中加载远程 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];
}

I'm loading a remote URL in a Webview, and I want to show a spinner while the content is loading. I have the following code, but the spinner doesn't go away when the content finishes loading. How do I make it so the spinner disappears after the content is loaded?

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];
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

御守 2024-08-25 18:57:36

成为框架加载委托,以及 当主框架完成加载时停止进度指示器的动画

仅当您收到 did-finish-load 消息的帧是 Web 视图的主帧时才停止动画。对于 Web 视图中的每个框架(包括嵌套框架和 iframe),您都会收到其中一条消息。您不想过早停止动画。

Be the frame load delegate, and stop the progress indicator's animation when the main frame finishes loading.

Only stop the animation when the frame that you received a did-finish-load message for is the web view's main frame. You'll get one of those messages for every frame in the web view, including nested frames and iframes. You don't want to stop the animation prematurely.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文