如何在应用程序启动时使用 UIWebView Iazy 加载和预渲染 ViewController?
我正在开发一个具有一系列分层 UITableViewController 的应用程序,直到您最终看到包含您正在查找的信息的 UIWebView。它工作得很好,除了当 UIWebView 加载时需要一段时间来渲染并在加载之前闪烁白色(我的所有视图,包括 UITableViewControllers 和 HTML 文件,都有黑色背景)
一旦 UIWebView 被加载并显示,它就没有那么多了一个问题 - 我让它在加载内容时加载一个带有黑色背景的空 HTML 页面 - 但第一次它总是很慢,并且给我白色的闪光。
我尝试通过初始化 UIWebView 并在之前的 UITableViewController 仍处于活动状态时加载它来预渲染 UIWebView,但它似乎不起作用。它允许我定义所有必要的参数,但是调用 loadView 方法,或者我尝试过的任何其他方法,都会诱使它在将 UIWebView 推到屏幕上之前实际加载黑色背景 HTML。
理想情况下,我希望它做的只是在应用程序启动后在后台初始化 UIWebView,这样当它被推送到导航堆栈供用户查看时,它已经预加载了黑色背景,因此没有白色闪光。
I'm working on an app that has a series of hierarchical UITableViewControllers, until you are eventually taken to a UIWebView that contains the information you're looking for. It works fine except that when the UIWebView loads it takes a while to render and flashes white before loading (All my views, including the UITableViewControllers and HTML files, have a black background)
Once the UIWebView has been both loaded and displayed it's not so much a problem- I have it load up an empty HTML page with a black background while it loads the content- but the first time it's always slow, and gives me the white flash.
I've tried to pre-render the UIWebView by initializing it and loading it while the previous UITableViewController is still active, but it doesn't seem to work. It lets me define all the necessary parameters, but calling the loadView method, nor anything else I've tried, has cajoled it into actually loading up that black background HTML before it pushes the UIWebView on screen.
Ideally what I'd like it to do is just initialize the UIWebView in the background once the app starts, such that by the time it gets pushed onto the navigation stack for the user to see, it's already preloaded with that black background so there's no white flash.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
webview.backgroundColor = [UIColor blackColor];
怎么样?How about
webview.backgroundColor = [UIColor blackColor];
?你找到并回答这个问题了吗?我也在做同样的事情。我发现我可以创建第二个网络视图并开始将其填充到屏幕外。我使用 javascript 来检查进度,以便我知道它已经呈现。然而,在我渲染了两个页面(一个可见,一个不可见)后大约 3 秒,它的网页崩溃线程。
我的下一个想法是让两个屏幕仅在右侧一英里之外的大部分未使用的屏幕上可见,这样最终用户就看不到它。
Did you find and answer to this. I am doing the same thing. I have found I can create a second webview and start populating it off screen. I use javascript to check on the progress, so that I know it has rendered. However about 3 seconds after I have two pages rendered (one visible and one not) it thread for web pages crashes.
My next idea is to make both screen visible just most the unused screen a mile off to the right so the end user can't see it.