Tom*_*ers 8 uiwebview webview xamarin.ios ios xamarin
我有一个UIWebView
内容缩放到适合.然后调整webview的大小以适应内容(见下文),并按预期工作.
webview还有一个滑动手势,用于加载新页面 - 当在下一页上执行a loadRequest
时,webview
会有一个瞬间闪烁回到webview的初始宽度.我已经确认使用a NSTimer
和UILabel
s 更改框架以显示框架的宽度.
这是重新调整大小的代码:
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;
}
Run Code Online (Sandbox Code Playgroud)
此代码由LoadFinished
webview上的委托调用.
我已经尝试设置webview的滚动视图的框架和webview的大小ContentSize
.
什么可能导致这种闪烁?
UIWebView 的 webViewDidFinishLoad 委托在加载网页期间将被多次调用,而轻弹的可能原因是您的网页大小不同,并且您试图通过将 UIWebView 的框架更改为内容大小来适应它们(根据您的代码) ,为什么不直接修复 UIWebView 的框架,让网页适合 UIWebView 呢?在网页的 css 中只使用“width: 100%”!
归档时间: |
|
查看次数: |
447 次 |
最近记录: |