Swift 3, iOS 10.3 - 在启动屏幕期间预加载 UIWebView [英] Swift 3, iOS 10.3 - Preload UIWebView during Launch Screen

查看:17
本文介绍了Swift 3, iOS 10.3 - 在启动屏幕期间预加载 UIWebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它在不同的 ViewControllers 上有 多个 WebViews,但加载它们每个需要大约 3 秒.是否可以在启动屏幕期间开始加载网页,或者当用户在 FirstViewController 上的网页上时加载 SecondViewController 的 WebView?

I have an App, which has multiple WebViews on different ViewControllers but it takes about 3 seconds to load each of them. Is it possible to start loading the webpages during the Launch Screen or to load the WebView of the SecondViewController when the user is on the webpage on the FirstViewController?

    import UIKit

    class dabs: UIViewController {
        @IBOutlet weak var webView_dabs: UIWebView!

    override func viewDidLoad() {
        super.viewDidLoad()
        let websiteURL = URL(string: "https://www.skybriefing.com/portal/dabs")
        let websiteURLRequest = URLRequest(url: websiteURL!)
        webView_dabs.loadRequest(websiteURLRequest)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
}

推荐答案

也许最好的方法是在视图控制器的视图上方放置一个与初始屏幕完全相同的临时视图.

Maybe the best way to do that is to put above your view controller's view a temporary view that is exactly the same as your splash screen.

将您的视图控制器作为委托添加到您的 UIWebView 并在方法 webViewDidFinishLoad: 中关闭临时视图.

Add your view controller as a delegate to your UIWebView and in the method webViewDidFinishLoad: just dismiss the temporary view.

理论上,用户只会认为启动画面花费了更多时间.

In theory, the user will just believe that the splashscreen has taken a bit more time.

这篇关于Swift 3, iOS 10.3 - 在启动屏幕期间预加载 UIWebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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