I am new in iOS programming and I am trying to have a view in storyboard with a UIImageView
on top and a uiWebView below it. I set a UIScrollView
that contains both of them and I would like that the scroll make the image disappearing while going down.
I follow this answer (link) and I got the scroll working but the UIWebView
does not resize itself properly. I have tried many solutions around, but if I get the web view resizing I do not get scroll working anymore and vice versa.
Particularly, I am using:
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
_textDetailNews.delegate = self; // the web view delegate
_textDetailNews.scrollView.scrollEnabled = NO;
[_textDetailNews loadHTMLString:description baseURL:nil]; // set text to be shown in web view
}
and
- (void)webViewDidFinishLoad:(UIWebView *)webview
{
CGFloat height = [[_textDetailNews stringByEvaluatingJavaScriptFromString:@"document.body.offsetHeight"] floatValue];
[_scrollView setContentSize: CGSizeMake(_scrollView.frame.size.width, height + _scrollView.frame.size.height)];
CGRect oldBounds = [[self textDetailNews] frame];
[_textDetailNews setFrame:CGRectMake(oldBounds.origin.x, oldBounds.origin.y, oldBounds.size.width, height)];
}
Where _scrollView
already contains the UIImageView
and the UIWebView
set from storyboard.
Please, I appreciate any help for make the scrolling and UIWebView
height resizing working.
EDIT
I am trying to make it more clear. The UIScrollView
works fine with the above code but the UIWebView
does not change its frame. While if I do not call: setContentSize
on _srollView
the UIWebView
change size but the view does not scroll anymore.
Can somebody told me where is the issue?