【问题标题】:UIPageViewController Scroll transition affects webView content loadingUIPageViewController 滚动过渡影响 webView 内容加载
【发布时间】:2014-08-09 15:51:22
【问题描述】:

我有一个包含 4 个视图的 UIPageViewController。这些视图中的每一个都具有以下布局: 每个视图都可以作为初始视图控制器访问,也称为pageViewController.currentPage。这 4 个视图中的每一个都包含一个 UIWebView,它在 init 方法中加载它的 HTML 内容。 UIWebViews 都是他们视图的宽度,320。我只需要它们匹配给定内容的高度,这样我就可以一直向下滚动内容。这实际上非常适合最初的viewController。我在webViewDidLoad 方法中调整了webView 的大小,如下所示:

self.scrollView.clipsToBounds = NO;
aWebView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin;
//NSLog(@"THIS IS WEBVIEWDIDFINISHLOAD IN ACTION");
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;

CGRect frame = aWebView.frame;
frame.size.height = 1;
aWebView.frame = frame;
CGSize fittingSize = [aWebView sizeThatFits:CGSizeZero];
frame.size = fittingSize;
aWebView.frame = frame;
scrollViewHeight = scrollViewHeight - self.articleTitleLabel.frame.size.height;
[self.scrollView setContentSize:(CGSizeMake(screenWidth, scrollViewHeight))];

CGSize fullContentSize = CGSizeMake(screenWidth, scrollViewHeight);
[self.scrollView setContentSize:fullContentSize];

self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,screenWidth, scrollViewHeight)];

aWebView.scrollView.scrollEnabled= NO;

问题是当你滑动到另一个viewController时,UIWebView的高度不够,网页内容被截断,UIScrollview是屏幕的高度。

***例外:这真的很奇怪,但它可能会帮助某人回答这个问题:如果您在初始 ViewController 出现后立即水平滑动并转到其他视图,他们的 webViews 将以正确的高度完美加载.问题依然存在,如果你加载一个ViewController,并花时间阅读该页面上的内容,然后滑动到另一个viewControllerwebView将被切断。

【问题讨论】:

    标签: ios objective-c uiwebview uiscrollview uipageviewcontroller


    【解决方案1】:

    我最终从这里使用了解决方案 3,并使 Scrollview 符合我的观点:UIWebView Doesn't Load Completely, Height Varies

    CGFloat height = [[aWebView stringByEvaluatingJavaScriptFromString:@"document.height"] floatValue];
    CGFloat width = [[aWebView stringByEvaluatingJavaScriptFromString:@"document.width"] floatValue];
    CGRect frame = aWebView.frame;
    frame.size.height = height + 130.0;
    frame.size.width = width;
    aWebView.frame = frame;
    
    //Scrollview height for my views
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    CGFloat screenWidth = screenRect.size.width;
    self.scrollView.contentSize=CGSizeMake(screenWidth, self.articleImgView.frame.size.height+self.articleContentWebView.frame.size.height);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 2013-06-29
      • 2013-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多