调整Web视图内容大小时确定UIWebView高度

时间:2017-01-24 06:52:34

标签: ios objective-c cocoa-touch

使用-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { CGRect frame1 = _widget_VW.frame; frame1.size.height = 60; _widget_VW.frame = frame1; [_widget_VW sizeToFit]; if (navigationType == UIWebViewNavigationTypeLinkClicked) { NSLog(@"User tapped a link."); [_widget_VW sizeToFit]; [_widget_VW setSuppressesIncrementalRendering:YES]; CGRect frame = _widget_VW.frame; frame.size.height = 1; _widget_VW.frame = frame; CGSize fittingSize = [_widget_VW sizeThatFits:CGSizeZero]; frame.size = fittingSize; _widget_VW.frame = frame; _VW_activity.hidden = NO; [_activityindicator startAnimating]; [self performSelector:@selector(setup_DATA) withObject:_activityindicator afterDelay:0.01]; return YES; } return YES; } 在我的视图控制器中加载小部件我希望在更改小部件内容大小时调整框架。

我的下面代码会在选择两次选项时返回原始高度

这是我的代码

list.contains

1 个答案:

答案 0 :(得分:0)

使用它。 它对我有用。

#pragma mark - UIWebViewDelegate methods
- (void)webViewDidFinishLoad:(UIWebView *)aWebView {
    CGRect frame = aWebView.frame;
    frame.size.height = 1;
    aWebView.frame = frame;
    CGSize fittingSize = [aWebView sizeThatFits:CGSizeZero];
    frame.size = fittingSize;
    aWebView.frame = frame;
}