我有多个pdf文件。根据用户输入,我正在使用UIWebView加载pdf。在第一次loadRequest时,它将正确加载pdf。从第二次调用LoadRequest开始,在加载新的pdf时显示出一些闪烁的效果。这意味着开始模糊显示内容,并在几秒钟内缓慢正确显示内容。

下面的代码段:

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

最佳答案

您可以使用以下命令在开始新请求之前清除Web视图

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


甚至

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


这样可以消除闪烁效果

关于ios - UIWebView loadRequest重用产生闪烁效果,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11222137/

10-10 20:26