Xcode 中的 Webview 加载微调器
我正在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
成为框架加载委托,以及 当主框架完成加载时停止进度指示器的动画。
仅当您收到 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.