【问题标题】:UIWebView inside UIScrollView does not display content properly?UIScrollView 内的 UIWebView 不能正确显示内容?
【发布时间】:2012-02-28 11:52:32
【问题描述】:

我在我的应用程序中显示 html 邮件。但它不会像苹果的邮件应用程序那样将图像拉伸到全尺寸。请参阅下面的屏幕截图。苹果如何知道如何实现这一目标?

  1. 我的应用程序 web 视图

Apple 的邮件应用

【问题讨论】:

  • 您能发布一个指向示例网页的链接吗?你能发布你如何在 webview 中嵌入 html 内容吗?

标签: html ios4 uiwebview


【解决方案1】:

我知道这不能回答你的问题,但 Apple 明确警告不要在 UIWebView 类参考中的 UIScrollViews 中嵌入 UIWebViews

Important You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled.

但是对于它的价值,您是否尝试过 UIWebView 的 scalesPageToFit 属性?

【讨论】:

  • 我没有在 scrollView 中嵌入 UIWebView。是的,我正在使用 scalePagesToFit = TRUE;
【解决方案2】:

您可以尝试在 HTML 中使用视口元标记。即使您无法在 HTML 加载之前对其进行修改,您也可以在事后添加/调整此标签。

我在这里回答了一个关于如何做到这一点的问题:

UIWebView -- load external website, programmatically set initial zoom scale, and allow user to zoom afterwards

【讨论】:

    【解决方案3】:

    不确定我在哪里有这个,但它在我的笔记中。
    您需要做一些 JS 工作才能使其在渲染后适应。

    #pragma mark -
    #pragma mark UIWebViewDelegate methods 
    -(void)webViewDidFinishLoad:(UIWebView *)webView{
    if (webView!=bioWebView)return;
    
    float h;
    
    NSLog(@"web view is %f high", bioWebView.frame.size.height);
    NSString *heightString = [bioWebView stringByEvaluatingJavaScriptFromString:@"document.getElementById("body").offsetHeight;"];
    NSLog(@"web content is %@ high",heightString);
    
    h = [heightString floatValue] +12.0f; // convert from string to float plus some extra points because calculation is sometimes one line short
    
    bioWebView.frame = CGRectMake(bioWebView.frame.origin.x, bioWebView.frame.origin.y, bioWebView.frame.size.width, h);
    
    // get bottom of text field
    h = bioWebView.frame.origin.y + h + 70; // extra 70 pixels for UIButton at bottom and padding.
    [scrollView setContentSize:CGSizeMake(320, h)];
    
    /* 
    
        position button code here.... 
    
        */
    
    }
    

    【讨论】:

      猜你喜欢
      • 2020-04-27
      • 1970-01-01
      • 1970-01-01
      • 2014-07-27
      • 1970-01-01
      • 2022-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多