【问题标题】:UIWebView problem with size adjustment when rotating device旋转设备时UIWebView大小调整问题
【发布时间】:2011-07-25 11:36:46
【问题描述】:

我有一个 UIWebview,其中放置了一个本地 html。当 ipad 移动时,我重新排列元素,以便 UIWebView 在案例之后更小/更大。问题是,虽然当我筛选和调整宽度时,虽然调整了宽度,但文本不是。该文本仅在 webview 的框架中可见,但它会在屏幕外显示(某些文本被隐藏,它会持续到某个点不可见)。如何调整 webview 内容宽度?

【问题讨论】:

  • 您可以在 webViewDidFinishLoad 方法中使用 UIWebViewDelegate 设置 webView 帧大小。

标签: iphone objective-c ios uiwebview


【解决方案1】:

我遇到过这个问题,我要解决的是这样的......创建一个方法

-(void)reconfigureFrame
{
       [_yourWebView loadHTMLString:[NSString stringWithFormat:@"<html><body style='background-color: transparent; width: 280px; margin: 0; padding: 0;color:black;'><div id='ContentDiv'>%@</div></body></html>",theStringToShow] baseURL:nil];
}

在 webView:DidLoad 委托方法中这样做

NSString *contentHeight = [webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('ContentDiv').offsetHeight"];
CGRect frame = [containtView frame];
//containtView holds webView
frame.size.height = [contentHeight floatValue] + 10;
[containtView setFrame:frame];

frame = [webView frame];
frame.origin.x = 10;
frame.origin.y = 5;
frame.size.width = containtView.frame.size.width - 2*frame.origin.x;
frame.size.height = [contentHeight floatValue];
[webView setFrame:frame];

在 didAutoRotate 中只调用第一个方法

【讨论】:

    猜你喜欢
    • 2017-03-19
    • 2018-05-02
    • 2018-11-11
    • 2013-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-29
    • 2012-01-06
    相关资源
    最近更新 更多