ios - Using Xcode and WKWebView I have a 1sec white screen while the webview loads. How can I stop this and only display webview when loaded? -


i have made simple webview app show web responsive website. have built launch screen , written code below. (*2) between launch screen , webview can see white screen 1-2 seconds. have searched stack overflow , found 2 solutions below not know how implement them. please may use code , provide example of how this? (*1)

(*1) solution 1.

 - (void)viewdidload {         [super viewdidload]; //objwebview outlet of uiwebview         [objwebview loadhtmlstring:@"<html><body style=\"background-color:black;\"></body></html>" baseurl:nil];          //the more delay errors less within 0.1-0.3 fine         [self performselector:@selector(loadurl:) withobject:nil afterdelay:0.1];      }  -(void)loadurl:(id)sender{     [objwebview stoploading]; //added line stop previous request     nsurl *url = [nsurl urlwithstring:@"http://www.google.com"];     nsurlrequest *req = [nsurlrequest requestwithurl:url];     [objwebview loadrequest:req]; 

solution 2;

// 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 delegate after loading // flicker fix  - (void)webviewdidfinishload:(uiwebview *)webview   {     [uiview beginanimations:nil context:nil];      [uiview setanimationduration:0.30];      self.webview.alpha = 1;      [uiview commitanimations];  } 

(*2)my code

import uikit  import webkit   class viewcontroller: uiviewcontroller {      @iboutlet weak var container: uiview!     var webview: wkwebview!      override func viewdidload() {         super.viewdidload()          webview = wkwebview()         container.addsubview(webview)     }           override func viewdidappear(animated: bool) {         let frame = cgrectmake(0, 0, container.bounds.width, container.bounds.height)          webview.frame = frame          loadrequest("weburlgoeshere")      }      override func didreceivememorywarning() {          super.didreceivememorywarning()           // dispose of resources can recreated      }  func loadrequest(urlstr: string) {      let url = nsurl(string: urlstr)!     let request = nsurlrequest(url: url)     webview.loadrequest(request)   } 

( sorry how code has copied on )


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -