表格的下拉放大 ----------王朋

表格下拉放大的效果是:

创建TableView和ImageView,分别设置相关属性:

_tableView=[[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    _tableView.delegate=self;
    _tableView.dataSource=self;
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
    //设置TableView的contentInset属性
     _tableView.contentInset=UIEdgeInsetsMake(imageHeight, 0, 0, 0);
    [self.view addSubview:_tableView];
    _imageView=[[UIImageView alloc] initWithFrame:CGRectMake(0, -imageHeight, self.view.frame.size.width,imageHeight )];
    _imageView.image=[UIImage imageNamed:@"icon.jpg"];
    //关键代码:UIViewContentModeScaleAspectFill,  contents scaled to fill with fixed aspect. some portion of content may be clipped.
    _imageView.contentMode=UIViewContentModeScaleAspectFill;
    
    [_tableView insertSubview:_imageView atIndex:0];

然后再在代理方法中改变图片的Frame

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGFloat h=scrollView.contentOffset.y;
    if (-h > imageHeight) {
        CGRect frame=_imageView.frame;
        frame.size.height=-h;
        frame.origin.y=h;
        _imageView.frame=frame;
    }
    
    NSLog(@"偏移量是%f",h);
}
原文地址:https://www.cnblogs.com/sixindev/p/4554544.html