0

我有一個UIPageViewController包含4個視圖。每個視圖都具有以下佈局: enter image description here 每個視圖都可以作爲初始視圖控制器也稱爲pageViewController.currentPage來訪問。這4個視圖中的每一個都包含一個UIWebView,它在init方法中加載它的HTML內容。 UIWebViews都是它們視圖的寬度,320。我只是需要它們來匹配給定內容的高度,以便我可以一直向下滾動瀏覽內容。這實際上適用於最初的viewController。我在webViewDidLoad方法大小的webView像這樣:UIPageViewController滾動轉移影響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出現時水平滑動並轉到其他視圖,則其webView將以正確的方式加載高度。問題仍然存在,如果您加載ViewController,並花時間閱讀該頁面上的內容,然後滑動到另一個viewControllerwebView將被切斷。

回答

0

我結束了使用的解決方案3從這裏,使滾動視圖適合自己的看法: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);