UIWebView resizes to loadRequest

I have a UIWebView in which content is scaled to fit. Then the webview will be modified according to the content (see below) and will work as expected.

The loadRequest also has a hard gesture attached to load new pages - when loadRequest executed on the webview for the next page, instant flicker returns to the initial width of the webview . I have confirmed that the frame is modified using NSTimer and UILabel to display the frame width.

Here is the code for recalibration:

 string bookHeightS = bookWebview.EvaluateJavascript ("document.getElementsByTagName('body')[0].scrollHeight"); string bookWidthS = bookWebview.EvaluateJavascript ("document.getElementsByTagName('body')[0].offsetWidth"); nfloat bookHeight = 0; nfloat.TryParse (bookHeightS, out bookHeight); nfloat bookWidth = 0; nfloat.TryParse (bookWidthS, out bookWidth); nfloat scaling = bookWebview.Frame.Height / bookHeight; nfloat initialWidth = bookWebview.Frame.Width; nfloat newWidth = scaling * bookWidth; CGRect frame = new CGRect (bookWebview.Frame.Location, new CGSize (newWidth, bookWebview.Frame.Height)); if (frame.Width != bookWebview.Frame.Width) { bookWebview.Frame = frame; } 

This code is called by the LoadFinished delegate in the LoadFinished .

I tried setting the webviewview scroll frame and webview ContentSize size.

What can cause this flicker?

flickering web view

+7
ios webview uiwebview xamarin
source share
2 answers

The UIWebView delegate webViewDidFinishLoad will be called several times during the loading of the web page, and there is a possible reason for clicking: you have a different size for your web pages and you are trying to set them by changing the UIWebView frame to the size of the content (according to your code), why would you just not lock your UIWebView frame and not allow your web page to fit your UIWebView? with only "width: 100%" on your css webpage!

+2
source share

resizing a web page frame is not entirely correct here. The LoadFinished handler is triggered when the load request [uiwebview loadRequest:] completes successfully and does not mean that the completion of your HTML content (DOM) is complete. There may be a few notes:

1 - make sure you include the view port tag in your HTML design to preserve the filling aspect. (in the head)

 <meta name="viewport" content="width=device-width, user-scalable=no"> 

2 - check the contents of the contents of the UIWebView interface (the default scale is the default). Also check incremental incremental rendering if necessary (depends on your design)

3 - It is almost impossible to catch when Dom elements are loaded and displayed in HTML. perhaps you can include some bootloader with a timeout there (do not forget to clear it when you unload the page)

4 - If you have some CSS standards for your design, you may need to consider the 100% width of the elements to fill the page.

5 - if you use autostart, just fix the UIWebview frame, and do not process the WebViewFrame with every hit.

What can I come up with, Good luck.

+1
source share

All Articles