一.位置确定
img = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
img.image = [UIImage imageNamed:@"headerImage1.jpg"];
UIView *v1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];
table.tableHeaderView = v1;
[v1 addSubview:img];
UIView *v2 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
table.backgroundView = v2;
[v2 addSubview:img];
二.实现滑动效果
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGRect tempRect = img.frame;
if (scrollView.contentOffset.y > 0) {
tempRect.origin.y = -scrollView.contentOffset.y;
img.frame = tempRect;
}else {
tempRect.origin.y = 0;
tempRect.size.height = 200 - scrollView.contentOffset.y;
img.frame = tempRect;
}
网友评论