I want to load HTML pages using WkWebView and I want to show the page just after it's finished loading. As long as it's loading I would like to show an activity indicator on an empty View. I create two view a loadingView and a wkWebView. While the page is loading I add to VC as subview the loadingView and after I want to remove loadingView and add wkWebView. Here is my code:
我想使用WkWebView来加载HTML页面,我想在页面加载完成后显示出来。只要它正在加载,我希望在一个空视图上显示一个活动指示器。我创建了两个视图一个loadingView和一个wkWebView。在页面加载时,我将其添加到VC中作为loadingView的子视图,并在删除loadingView并添加wkWebView之后。这是我的代码:
[self addSubview:_loadingView];
_wkWebView = [[WKWebView alloc] initWithFrame:self.frame];
_wkWebView.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, self.frame.size.height);
//Send a request to wkUrlconnection
NSURL *wkUrl = [NSURL URLWithString:self.wkUrlString];
NSURLRequest *wkRequest = [NSURLRequest requestWithURL:wkUrl];
//Here I want to check if it's loaded and then remove loadingView and add wkWebView
[_wkWebView loadRequest:wkRequest];
[self.loadingView removeFromSuperview];
[self addSubview:_wkWebView];
Can someone show me how to check while it's loading and if finish refresh the VC? Thank you for your answers.
有人能告诉我如何在加载时检查,如果完成刷新VC吗?谢谢你的回答。
1 个解决方案
#1
31
I think the WKNavigationDelegate
's webView:didFinishNavigation: delegate callback is what you're looking for.
我认为WKNavigationDelegate的webView:didFinishNavigation: delegate callback是你要找的。
Configure and present your activity indicator when you start to load and then stop and remove it from view when the callback is called.
在开始加载时配置并显示活动指示器,然后在调用回调时停止并将其从视图中删除。
#1
31
I think the WKNavigationDelegate
's webView:didFinishNavigation: delegate callback is what you're looking for.
我认为WKNavigationDelegate的webView:didFinishNavigation: delegate callback是你要找的。
Configure and present your activity indicator when you start to load and then stop and remove it from view when the callback is called.
在开始加载时配置并显示活动指示器,然后在调用回调时停止并将其从视图中删除。