Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preloading a UIWebView, avoiding white screen flash

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.

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.

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."

like image 782
Ascendant Avatar asked May 13 '11 03:05

Ascendant


1 Answers

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];
}

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 :)

like image 178
Inder Kumar Rathore Avatar answered Oct 21 '22 03:10

Inder Kumar Rathore