复习scrollview知识:contentInset(top,left,bottom,right),contentOffset(x,y)
在tableview 的顶部addSubview,之前首先设置tableview的contentInset,预留出要添加的scrollView的frame空间;
self.tableView.contentInset = UIEdgeInsetsMake(HEIGH, 0, 0, 0);```
######在tableview 的顶部addSubview
UIScrollView*scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, -HEIGH, [UIScreen mainScreen].bounds.size.width, HEIGH)];
scrollView .tag = 222;
//scrollView .image = [UIImage imageNamed:@"IMG_0767.JPG"];
//imageView.contentMode = //UIViewContentModeScaleAspectFill;
//imageView.tag = 111;
[self.tableView addSubview:scrollView ];```
tableview 继承自scrollview,scrollview的滑动事件;
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGPoint point = scrollView.contentOffset;
if (point.y < -HEIGH) { //1.判断处在“下拉状态”;point.y是负值;
//2. 得到tableView上方的scrollview;获取frame值;
CGRect rect = [self.tableView viewWithTag:222].frame;
//3. 设置scrollview的origin.y是其起点始终保持在屏幕的最上方;
rect.origin.y = point.y;
//4. 设置scrollview的height保持和下拉高度一致;
rect.size.height = -point.y;
[self.tableView viewWithTag:222].frame = rect;
}
//设置scrollview里面的当前的imgview的contentMode
//1.获取当前的scrollview里面的imgView;
conrrentImgView = [scrollview subviews][currentPageNumber];
//2.设置当前的imgView 的contentMode,图片的高度变化,宽度同比例变大。
conrrentImgView .contentMode = UIViewContentModeScaleAspectFill;
}```
[######略后补发动图]