ios tableview下拉头部图片变大

#import "ViewController.h"

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView *mytableview;
@property(nonatomic,retain)NSMutableArray *listenArray;
@property(nonatomic,retain)UIImageView *imageView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.listenArray = [NSMutableArray array];
    
    self.mytableview=[[UITableView alloc]initWithFrame:CGRectMake(0, 64, 375 , 667  - 49-64) style:UITableViewStylePlain];
    [self.view addSubview:self.mytableview];
    //    [_tableView release];
    self.mytableview.delegate = self;
    self.mytableview.dataSource = self;
    self.mytableview.contentInset = UIEdgeInsetsMake(220 , 0, 0, 0);
    self.mytableview.separatorStyle = 0;

    //相对于0点,图片坐标应该是(0,-200)
    self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, -220 , self.view.frame.size.width, 220 )];
    self.imageView.image = [UIImage imageNamed:@"afaded9fb75cfcf92bab35347d8e8ab8.jpg"];
    //设置imageView高度改变时宽度也跟着改变
    self.imageView.contentMode = UIViewContentModeScaleAspectFill;
    [self.mytableview addSubview:self.imageView];
  }
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
    }
    cell.textLabel.text=@"123";
     return cell;
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    //刚开始y的偏移量初始值就是-220
    //    //NSLog(@"y1 === %f",scrollView.contentOffset.y);
    CGFloat y = scrollView.contentOffset.y ;//第一次是-220
    //    //NSLog(@"y2 === %f",y);
    
    if (y < -220 ) {
        CGRect frame = self.imageView.frame;
        frame.origin.y = y;//imageView的frame是不断往上偏移
        frame.size.height =  -y;//tablview向下偏移了多少,高度就增长多少
        self.imageView.frame = frame;
    }
    
}
相关文章
相关标签/搜索