预加载一个UIWebView,避免白屏闪烁

Preloading a UIWebView, avoiding white screen flash(预加载一个UIWebView,避免白屏闪烁)

本文介绍了预加载一个UIWebView,避免白屏闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个具有表格导航的应用程序,以最终深入到显示各种信息的 UIWebView.然而,从 UITableView 的流畅性到 UIWebView 的缓慢性的转变对用户来说是不和谐的,所以我想尽我所能改善这种体验.

I'm working on an app that has table navigation to eventually drill down to UIWebView that displays various information. However, the transition from the slickness of UITableView to the slow wonkiness of UIWebView is jarring for the user so I want to improve that experience however I can.

具体来说,tableViewsUIWebView 页面的背景都是黑色背景,但是当我打开 UIWebView 时,它会闪烁空白色大约一秒钟(本地和远程 HTML 文件都是这种情况.)我如何(理想情况下)预加载此过程,或者(至少)使flash"全黑而不是全白?我尝试将视图/webView 的背景设置为黑色,但这似乎没有帮助.

Specifically, the background of both the tableViews and UIWebView pages have black backgrounds, but when I open the UIWebView it flashes empty white for about a second (this is the case for both local and remote HTML files.) How can I (ideally) preload this process, or (at least) make the "flash" be all black rather than all white? I tried making the view / webView's background black but that didn't seem to help.

现在在我的应用程序中,当用户选择一个单元格时,应用程序只会加载 UIWebView 子类并将其推送到导航堆栈上.UIWebView 子类有一个以 & 开头的活动指示器.在 WebViewDidStartLoad 和 WebViewDidFinishLoad 上停止动画,效果很好,但对白色闪光"没有任何帮助.

In my app right now, when a user selects a cell, the app just loads up the UIWebView subclass and pushes it on the navigation stack. The UIWebView subclass has an activity indicator that starts & stops animating on WebViewDidStartLoad and WebViewDidFinishLoad, which works fine, but it doesn't do anything to help the "white flash."

推荐答案

我已经测试过了...我正在发送我用过的两个方法...

I have tested it... I'm sending the two method that I have used...

 - (void)viewDidLoad {
        [super viewDidLoad]; //objWebView is the outlet of UIWebView
        [objWebView loadHTMLString:@"<html><body style="background-color:black;"></body></html>" baseURL:nil];

        //the more the delay the errors will be less so within 0.1-0.3 would be fine
        [self performSelector:@selector(loadURL:) withObject:nil afterDelay:0.1]; 
    }

-(void)loadURL:(id)sender{
    [objWebView stopLoading]; //added this line to stop the previous request
    NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
    NSURLRequest *req = [NSURLRequest requestWithURL:url];
    [objWebView loadRequest:req];
}

这里我在 0.1 秒后执行请求,否则它会像你的情况一样看起来是白色的.或者你可以根据时间给你的延迟时间.干杯:)

here I'm performing the request after 0.1 sec, other wise it will look white as in your case. Or you can give your delay time depending upon the time.. Cheers :)

这篇关于预加载一个UIWebView,避免白屏闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:预加载一个UIWebView,避免白屏闪烁

基础教程推荐