Sma*_*per 1 javascript iphone uiwebview ios
我在View中添加了UIWebView,在ScrollView中添加了该视图.
我想得到UIWebView内容的框架.那么我可以设置框架来查看和滚动查看吗?
我知道我们可以通过使用javascript获得高度.如下所述:
float height = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight;"] floatValue];
Run Code Online (Sandbox Code Playgroud)
但是当我旋转视图并重新计算didRotateFromInterfaceOrientation::(UIInterfaceOrientation)fromInterfaceOrientation方法中UIWebView内容的高度时,内容高度增加了.
所以请建议我在旋转方向时如何获得合适的高度?
谢谢.
采用这种方法:
- (void) webViewDidFinishLoad:(UIWebView *)webView{
CGRect frame = wvContent.frame;
CGSize fittingSize = [wvContent sizeThatFits:CGSizeZero];
frame.size = fittingSize;
wvContent.frame = frame;
}
Run Code Online (Sandbox Code Playgroud)
然后每次设备旋转时调用此方法:
- (void) reloadContent
{
CGRect frame = wvContent.frame;
frame.size.height = 1;
frame.size.width = wvContent.frame.size.width; // you should change webview's width here.
wvContent.frame = frame;
[wvContent loadHTMLString:yourHTML baseURL:nil]; // reload webview
}
Run Code Online (Sandbox Code Playgroud)
希望有帮助:)
| 归档时间: |
|
| 查看次数: |
5746 次 |
| 最近记录: |