gpt4 book ai didi

ios - 计算我的 UIWebView 的高度?

转载 作者:行者123 更新时间:2023-11-29 02:09:06 25 4
gpt4 key购买 nike

我正在尝试根据 UIWebView 将显示的内容计算其所需的高度。所以我着手编写了以下代码:

_textView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 80, self.view.frame.size.width-20, self.view.frame.size.height+self.view.frame.size.height+self.view.frame.size.height )];
_commentsViewContainer = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetHeight(_backgroundScrollView.frame), CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame) - kBarHeight )];
[_commentsViewContainer addGradientMaskWithStartPoint:CGPointMake(0.5, 0.0) endPoint:CGPointMake(0.5, 0.03)];
_commentsTableView = [[UIScrollView alloc] initWithFrame:CGRectMake(15, 0, self.view.frame.size.width-30, CGRectGetHeight(self.view.frame) - kBarHeight )];
_commentsTableView.scrollEnabled = NO;

...

[_mainScrollView addSubview:_backgroundScrollView];
[_commentsTableView addSubview:_visitWebsite];
[_commentsTableView addSubview:shareButton];
[_commentsTableView addSubview:_textView];
[_commentsViewContainer addSubview:_commentsTableView];
[_mainScrollView addSubview:_commentsViewContainer];

因此,在 UIWebView 完成加载后,我执行以下操作:

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
NSString *output = [webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight;"];
NSInteger myInt = [output intValue];

NSLog(@"Calculated height is: %d", myInt);

CGRect nextFrame = _textView.frame;
nextFrame.size.height = myInt + 200;
_textView.frame = nextFrame;

CGRect nexterFrame = _commentsTableView.frame;
nexterFrame.size.height = myInt + 200;
nexterFrame.origin.y = 0;
_commentsTableView.frame = nexterFrame;

CGRect nextererFrame = _commentsViewContainer.frame;
nextererFrame.size.height = myInt + 200;
nextererFrame.origin.y = 0;
_commentsViewContainer.frame = nextererFrame;

_backgroundScrollView.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height + myInt);
}

但是,它的大小仍然不正确,并且文本被切断。我在这里做错了什么?

最佳答案

此代码可能会有所帮助。

-(void)webViewDidFinishLoad:(UIWebView *)webView {
NSLog(@"%f", webView.scrollView.contentSize.height);
}

关于ios - 计算我的 UIWebView 的高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29477793/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com