iOS 头部视图下拉变大

557 阅读1分钟

都在代码里,直接上代码

//改变tableView的内边距
self.tableView.contentInset = UIEdgeInsetsMake(200, 0, 0, 0);
//这里创建的视图Y和高没有卵用,希望知道的同志告知一下
    self.headerView = [[UIView alloc] initWithFrame:CGRectMake(0, -200, self.view.frame.size.width, 0)];
    self.headerView.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:.8];
//在这里创建的视图一定要添加到tableView上,而不是给头视图赋值
    [self.tableView addSubview:self.headerView];

*****
想要宽高等比例缩放加上这句代码
self.headerView.contentMode = UIViewContentModeScaleToFill;

在scrollView代理方法里实现视图大小的改变

-(void)scrollViewDidScroll:(UIScrollView *)scrollView{

    CGFloat yOffset  = scrollView.contentOffset.y;
    if (yOffset < -200) {
        CGRect f = self.headerView.frame;
        f.origin.y = yOffset;
        f.size.height =  -yOffset;
        self.headerView.frame = f;
    }
  
}