如何在页面快速加载时显示图像? [英] How to show image while page is loading in swift?

查看:37
本文介绍了如何在页面快速加载时显示图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 swift 和 Xcode 的初学者,想知道如何在 UIWebView 中完成页面加载时显示图像,例如当您进入一个新网站时,图像开始出现在 webview 的屏幕上

I'm beginner in swift and Xcode and want to know how to make an image appears while page finish loading in UIWebView,like when you enter a new website,image start appear on screen in webview

推荐答案

您可以在网站加载的同时使用任何加载器,例如 MBProgressHUD 或任何其他进度条.

You can use any loader meanwhile the website loads, like MBProgressHUD or any other progress bar.

如果您愿意在加载时在屏幕上显示自定义图像,那么您可以使用以下委托方法处理:

And if you are willing to show an custom image over a screen while loading then you can handle that in following delegate methods:

假设您拍摄了名为 loadingView

func webView(webView: UIWebView!, didFailLoadWithError error: NSError!) {
**loadingView**.viewWithTag(1)?.hidden = true 
print("Webview fail with error \(error)");
}

**func webView(webView: UIWebView!, shouldStartLoadWithRequest request: NSURLRequest!, navigationType: UIWebViewNavigationType) -> Bool {**
return true;
}

func webViewDidStartLoad(webView: UIWebView!) {
**loadingView**.viewWithTag(1)?.hidden = false 
print("Webview started Loading")
}

func webViewDidFinishLoad(webView: UIWebView!) {
**loadingView**.viewWithTag(1)?.hidden = true 
print("Webview did finish load")
}

希望对您有所帮助.

这篇关于如何在页面快速加载时显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆