iOS 实现webview不滚动,显示所有内容

self.first_webview 为:web view   height1 为:web view内容高度  self.scrollSuperView  为:滚动式图scrollview

1. 首先我们要在底部放一个scrollview,在上面放置一个webview,接下来便是禁止webview滚动。

2. 实现web view不滚动

 UIScrollView *first_tempView  = (UIScrollView *)[self.first_webview.subviews objectAtIndex:0];
 first_tempView.scrollEnabled = NO;

3.遵守web view的协议

4. 计算web view内容的高度

- (void)webViewDidFinishLoad:(UIWebView *)webView{
   height1 = [[self.first_webview stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"] floatValue];     NSLog(@"self.first_webview = %f",height1);   
}
5.
//获取到实际高度后,设置self.scrollSuperView的contentSize 高度显示自己可以定
self.scrollSuperView.contentSize = CGSizeMake(0, height1+SCREEN_HEIGHT);

6.这样便实现了webview不滚动,也能实现内容全部显示。

你可能感兴趣的:(苹果,iOS,OC)