Siva
Siva

Reputation: 608

UIWebView loadRequest reuse gives flickering effect

I have multiple pdf files. Based on user input i am loading the pdf using UIWebView. On first loadRequest it loads the pdf properly. From second call to LoadRequest onwards its showing some flickering effect while loading the new pdf.. Meaning that starts blur display of content and slowly display content properly in few secs.

Code snippet below:

- (void) loadDocument: (NSString *) documentName
{
    NSString * path = [[NSBundle mainBundle] pathForResource: documentName ofType: self.docType];
    NSURL * url = [NSURL fileURLWithPath: path];
    request = [NSURLRequest requestWithURL: url];
    [PdfWebView loadRequest: request];    
}


- (void) loadNewDoc:(int)segIndex
{
    switch (mPageIndex) 
    {
                case 0:
                    [self loadDocument:@"PDF_0"];
                    break;

                case 1:
                    [self loadDocument:@"PDF_1"];
                    break;


                case 2:
                    [self loadDocument:@"PDF_2"];
                    break;


                default:
                    break;
        }
}

Upvotes: 0

Views: 889

Answers (2)

Mirko
Mirko

Reputation: 1

for me, this helped (its robovm java code):

UIView.transition(_wv, 0.5, UIViewAnimationOptions.TransitionCrossDissolve, new Runnable() {
@Override
public void run() {
    _wv.loadData(new NSData(pdf), "application/pdf", "utf-8", null);
}
}, null);

Upvotes: 0

Omar Abdelhafith
Omar Abdelhafith

Reputation: 21221

You can clear the web view before starting the new request by using

[yourwebview loadHTMLString:@"<html><head></head><body></body></html>" baseURL:nil];

Or even

[yourwebview stringByEvaluatingJavaScriptFromString:@"document.open();document.close();"];

This may remove the flickering effect

Upvotes: 2

Related Questions