下拉放大headView

#import "ViewController.h"

#define width  self.view.bounds.size.width

@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>

{

    UITableView *_tableView;

    UIView *_hearderView;

    UIImageView *_imgView;


}

@end


@implementation ViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    _tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];

    _tableView.delegate = self;

    _tableView.dataSource = self;

    

    _hearderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, width, 200)];

    _imgView = [[UIImageView alloc]initWithFrame:_hearderView.frame];

    UIImage *img = [UIImage imageNamed:@"1"];

    _imgView.image = img;

    [_hearderView addSubview:_imgView];

    _tableView.tableHeaderView = _hearderView;

    [self.view addSubview:_tableView];

    

}

//指定每组的单元格的个数

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{


    return 10;

}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];

    

    return cell;


}

//实现下拉放大


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

//    纵向偏移,y

    CGFloat ysffset = _tableView.contentOffset.y;

//    向上偏移,偏移量为正,向下偏移,偏移量为负

    if (ysffset<-64){

//        ABS 绝对值

//        factor/200 比值,表示偏移后的高度/原始高度

        CGFloat factor = ABS(ysffset)+200-64;

        CGRect  f = CGRectMake(-(width*factor/200-width)/2, -ABS(ysffset)+64, width*factor/200, factor);

        _imgView.frame =f;

    

    }else{

//        frame不可以直接更改

        CGRect f = _hearderView.frame;

        f.origin.y =0;

        _hearderView.frame = f;

    

        _imgView.frame = CGRectMake(0, f.origin.y, width, 200);

    }



}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值