How to prevent initial white flash when showing a UIWebView?

后端 未结 4 1528
北恋
北恋 2020-12-08 14:28

I use a UIWebView to show an \"About\" screen by displaying a bundled HTML file. My app\'s view hierarchy is: UITabBarController / UIViewCont

相关标签:
4条回答
  • 2020-12-08 14:53

    Fixed by adding in webView settings:

    myWebView.setBackgroundColor(0x00000000);
    
    0 讨论(0)
  • 2020-12-08 14:57

    I also encountered the same problem , the solution I found is as follows.

    -(void)viewDidLoad {
      [super viewDidLoad];
    
      [_webView setOpaque:NO];
      _webView.backgroundColor = [UIColor clearColor];
      self.webView.hidden = YES;
    }
    
    -(void)webViewDidFinishLoad:(UIWebView *)webView {
    
     //...........................
    
     self.webView.hidden = NO;
    }
    
    0 讨论(0)
  • 2020-12-08 15:04

    Swift:

    webView.isOpaque = false
    webView.backgroundColor = UIColor.clear
    

    Objective-C:

    webView.opaque = NO;
    webView.backgroundColor = [UIColor clearColor];
    
    0 讨论(0)
  • 2020-12-08 15:07

    // load index.html

    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"www"]];
    self.webview.delegate = self;
    
    self.webview.alpha = 0; // flicker fix 
    
    [self.webview loadRequest:[NSURLRequest requestWithURL:url]];
    

    Add this to delegate after loading

    // flicker fix
    
    - (void)webViewDidFinishLoad:(UIWebView *)webView  
    {
        [UIView beginAnimations:nil context:nil];
    
        [UIView setAnimationDuration:0.30];
    
        self.webview.alpha = 1;
    
        [UIView commitAnimations];
    
    }
    
    0 讨论(0)
提交回复
热议问题