预加载UIWebView,避免白屏闪烁 [英] Preloading a UIWebView, avoiding white screen flash

查看:204
本文介绍了预加载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.

具体来说, tableViews 的背景UIWebView 页面有黑色背景,但当我打开 UIWebView 时,它会闪烁空白白色大约一秒钟(本地和远程都是如此) HTML文件。)我如何(理想情况下)预加载此过程,或者(至少)使闪光全部为黑色而不是全白?我尝试将视图/ 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,避免白屏闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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