我们想要头部添加到webView上,而且能随着滚动,我们就要明白
webView之所以能够显示这么多的内容,而且可以滚动就是因为这个scrollView的属性,所以,我们想要头部视图也可以滚动,就得将头部视图加在ScrollView上。
我们在视图上添加完webView之后,我们将webView的scrollView的的contentInset设置一下,contentInset可以在四周增加滚动范围.
//
创建
webView
self.
webView
= [[
UIWebView
alloc
]
initWithFrame
:
CGRectMake
(
0
,
0
,
KProjectScreenWidth
,
KProjectScreenHeight
-
113
)];
// 290
self.
webView
.
backgroundColor
= [
UIColor
whiteColor
];
self.
webView
.
scrollView
.
backgroundColor
= [
UIColor
whiteColor
];
[
self.
webView setScalesPageToFit:YES];
[
self
.
view
addSubview
:
self
.
webView
];
//
注意:UIEdgeInsetsMake的值依次设置为:上,左,下,右
self.
webView
.
scrollView
.
contentInset
=
UIEdgeInsetsMake
(
290
,
0
,
0
,
0
);
//
将头部视图添加到
webView.scrollView上
XZWebTopView
*topWeb = [[
XZWebTopView
alloc
]
initWithFrame
:
CGRectMake
(
0
,-
290
,
KProjectScreenWidth
,
290
)];
[self.webView.scrollView addSubview:topWeb];
// 加载数据
[
self
.
webView
loadHTMLString
:modelGetTogether.
party_info
baseURL
:[
NSURL
URLWithString
:urlPath]];
//
但是当网络加载较慢的时候,会出现如下情况:底下是一块黑色的
// 解决方法是:
self.
webView
.
scrollView
.
contentOffset
=
CGPointMake
(
0
, -
290
);
contentInset和
contentOffset要一起写