UIPageViewController滚动转换会影响webView内容加载

时间:2014-06-19 07:26:26

标签: ios objective-c uiwebview uiscrollview uipageviewcontroller

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

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将被切断。< / p>

1 个答案:

答案 0 :(得分:0)

我最终从这里使用解决方案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);