UIWebView scrollView.contentSize.height not changed

After loading the htmlString contentSize scrollView in the UIWebView does not change. In my other form, the controllers are all good, but now it's something mysterious.

I have

 UIWebView *contentWebView; 

I do this in some method

 - (void)makeContent { ... contentWebView = [[UIWebView alloc] initWithFrame:CGRectMake(5, imageView.originY + imageView.height + 5, mainView.width - 10, 100)]; contentWebView.delegate = self; contentWebView.scrollView.scrollEnabled = NO; contentWebView.contentMode = UIViewContentModeScaleAspectFit; NSLog(@"%@", factDict[@"text"]); [contentWebView loadHTMLString:factDict[@"text"] baseURL:nil]; contentWebView.height = contentWebView.scrollView.contentSize.height; [mainView addSubview:contentWebView]; } - (void)webViewDidFinishLoad:(UIWebView *)webView { NSLog(@"%f %f %f %f ", webView.height, webView.scrollView.contentSize.height, contentWebView.height, contentWebView.scrollView.contentSize.height); [webView sizeToFit]; NSLog(@"%f %f %f %f ", webView.height, webView.scrollView.contentSize.height, contentWebView.height, contentWebView.scrollView.contentSize.height); ... } 

At the beginning of other controllers contentWebView.height = contentWebView.scrollView.contentSize.height; help me but now it doesn't work

In the magazine I have the following

enter image description here

So I don’t understand why contentize.height is not changed

EDIT

In my other viewcontrollers all is good

 - (void)makeScrollView { CGFloat width = [Utils widthOfMainViewForOrientation:self.interfaceOrientation]; [mainView removeFromSuperview]; mainView = [[UIView alloc] initWithFrame:CGRectMake((self.view.width - width) / 2, 15, width, 100)]; mainView.backgroundColor = [UIColor whiteColor]; if ([self.fullInfoDictionary[@"content"] length]) { contentWebView = [[UIWebView alloc] initWithFrame:CGRectMake(6, 4, mainView.width - 12, 100)]; contentWebView.contentMode = UIViewContentModeScaleAspectFit; contentWebView.delegate = self; HelperDf.htmlString = self.fullInfoDictionary[@"content"]; [contentWebView loadHTMLString:self.fullInfoDictionary[@"content"] baseURL:nil]; contentWebView.scrollView.scrollEnabled = NO; [mainView addSubview:contentWebView]; } [self.scrollView addSubview:mainView]; } - (void)webViewDidFinishLoad:(UIWebView *)webView { contentWebView.height = contentWebView.scrollView.contentSize.height; NSLog(@"%f %f %f %f", webView.height, webView.scrollView.contentSize.height, contentWebView.height, contentWebView.scrollView.contentSize.height); [self reloadFrames]; } 

I have the following

enter image description here

I get htmlString from this controller

 HelperDf.htmlString = self.fullInfoDictionary[@"content"]; 

And install in my first UIWebVIew, but the results are NO.

You can do this regardless of whether I contentWebView.scrollView.scrollEnabled = NO; , I turn to YES, but the results are the same - in the second case, everything is fine in the first - NO

+4
source share
3 answers

You need to change NO to YES to your contentWebView.scrollView.scrollEnabled , e.g.

  contentWebView.scrollView.scrollEnabled = YES; 

EDITED

 - (void)webViewDidFinishLoad:(UIWebView *)webView { [webView sizeToFit]; webView.scrollView.contentSize = CGSizeMake(320, contentWebView.scrollView.contentSize.height + 60); } 
0
source

The problem is that your performance is not yet visible. The values ​​you are looking for are displayed only after they are added to the view, which is on the view stack.

Somewhere along the way, it seems that your view is not being added while you are checking your values.

0
source

The problem is that your performance is not yet visible. The values ​​you are looking for are displayed only after they are added to the view, which is on the view stack.

I fixed my problem with the above

-one
source

Source: https://habr.com/ru/post/1497374/


All Articles