How to prevent initial white flash when showing a UIWebView?
// 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];
}
Swift:
webView.isOpaque = false
webView.backgroundColor = UIColor.clear
Objective-C:
webView.opaque = NO;
webView.backgroundColor = [UIColor clearColor];
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;
}