简体   繁体   English

UIWebView scrollView.contentSize.height 没有改变

[英]UIWebView scrollView.contentSize.height not changed

After load htmlString, contentSize of scrollView in UIWebView don't changed.加载 htmlString 后, UIWebView scrollView 的 contentSize 不会改变。 In other my viewControllers all good, but now it's something mysterious在其他我的 viewControllers 都很好,但现在有点神秘

I have我有

UIWebView *contentWebView;

I make it 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);
...
}

Early in other controllers contentWebView.height = contentWebView.scrollView.contentSize.height;早期的其他控制器contentWebView.height = contentWebView.scrollView.contentSize.height; help me, but now it's not work帮助我,但现在它不起作用

In log I have next在日志中我有下一个

在此处输入图片说明

So I don\\t understand why contentsize.height not changed所以我不明白为什么 contentsize.height 没有改变

EDIT编辑

In my another viewcontrollers all 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 next我有下一个

在此处输入图片说明

I get htmlString from this controller我从这个控制器得到 htmlString

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

And set in my first UIWebVIew but results - NO.并在我的第一个 UIWebVIew 中设置但结果 - 否。

You can it's no matter if stay contentWebView.scrollView.scrollEnabled = NO;你可以不管是否留contentWebView.scrollView.scrollEnabled = NO; I change to YES, but results are same - in second case all good in first - NO我改为是,但结果是一样的 - 在第二种情况下,第一种情况都很好 - 没有

You need to change NO to YES your contentWebView.scrollView.scrollEnabled , such like您需要将NO更改为YES您的contentWebView.scrollView.scrollEnabled ,例如

 contentWebView.scrollView.scrollEnabled = YES;

EDITED已编辑

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

The problem is that your view isn't visible yet.问题是您的视图尚不可见。 The values you are looking for are only made visible once it is added to a view which is in the view stack.您正在查找的值仅在将其添加到视图堆栈中的视图后才可见。

Somewhere along the way it seems that your view isn't added to at the time when you are checking your values.在此过程中的某个地方,在您检查值时似乎没有添加您的视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM