UIWebView内容在更改方向时部分丢失?

时间:2014-07-25 17:09:39

标签: ios objective-c uiwebview uiscrollview screen-orientation

我正在为iPad构建文章阅读应用并使用分割视图控制器 UIViewController包含uiscrollview作为子视图,uiscrollview包含uiwebview作为子视图和三个标签。
我已经禁用了uiwebview的滚动,并根据uiwebview的内容大小和uiscrollview中的标签设置滚动高度。
当我将方向肖像更改为横向时,我将面临一个问题。我在uiweview中的内容部分丢失。

enter image description here

这是我的代码:

   - (void)webViewDidFinishLoad:(UIWebView *)webView
     {
      CGSize mWebViewTextSize = [webView sizeThatFits:CGSizeMake(1.0f, 1.0f)];  // Pass about any size

      CGRect mWebViewFrame = webView.frame;
      mWebViewFrame.size.height = mWebViewTextSize.height;
      webView.frame = mWebViewFrame;
      webView.scrollView.scrollEnabled = NO;
      webView.scrollView.bounces = NO;
      scroller.translatesAutoresizingMaskIntoConstraints  = NO;
      webView.translatesAutoresizingMaskIntoConstraints = NO;

     scroller.contentSize = CGSizeMake(scroller.frame.size.width, webView.frame.size.height+260);

   for (id subview in webView.subviews)
     {
       if ([[subview class] isSubclassOfClass: [UIScrollView class]])
      {
        [subview setBounces:NO];
        [subview setScrollEnabled:NO];

            }
         }
      }

1 个答案:

答案 0 :(得分:0)

您需要调整WebView的框架根据iPad的方向,TRy根据UIInterfaceOrientation上的视图框架调整Webview的框架并重新加载webview