I have a UIPageViewController
that contains 4 views. Each of these views has the following layout:
Each view can be accessed as the initial view controller also know as
pageViewController.currentPage
. Each of these 4 views contains a UIWebView
that loads it's HTML content in the init method. The UIWebViews
are all the width of their view, 320. I just need them to match the height of the given content, so that I can scroll all the way down through the content. This actually works perfectly for the initial viewController
. I sized the webView
in the webViewDidLoad
method like so:
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;
THE PROBLEM is that when you swipe to another viewController
, that UIWebView
is not the adequate height, and the web content is cutoff, and the UIScrollview
is the height of the screen.
***EXCEPTION: This is really weird, but it may help someone to answer the question: If you swipe horizontally as soon as the initial ViewController appear and go to the other views, their webViews will load perfectly with the correct height. The problem still remains that if you load up a ViewController
, and take your time to read the content on that page, then swipe to another viewController
, the webView
will be cut off.