TableView头部图片下拉图片放大

浏览商品时,组头放置的商品图片,下拉UITableView,会有头部图片放大的效果

1.宏定义 

#define WIDTH [[UIScreen mainScreen] bounds].size.width

#define HEIGHT [[UIScreen mainScreen] bounds].size.height

#define  NavigationBarHeight 64

#define  ImageHeight 250


2.遵循协议、定义属性

@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong)UITableView *tableView;

//底层背景图

@property(nonatomic,strong)UIImageView *zoomImageView;

//图像

@property(nonatomic,strong)UIImageView *circleView;

//昵称

@property(nonatomic,strong)UILabel *label;

3.上代码

   //1.初始化_tableView

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

    //2.设置代理

    self.tableView.dataSource=self;

    self.tableView.delegate=self;

    //3.设置contentInset属性(上左下右的值)

    self.tableView.contentInsetUIEdgeInsetsMake(ImageHight+64,0,0,0);

    //4.添加tableView

    [self.view addSubview:self.tableView];

    //5.配置ImageView

    self.zoomImageView=[[UIImageView alloc]initWithImage:[UIImageimageNamed:@"123.jpg"]];

    self.zoomImageView.frame CGRectMake(0, -ImageHight ,self.view.frame.size.width,ImageHight);

    //核心代码

    //UIViewContentModeScaleAspectFill高度改变,宽度也会改变

    //不设置那将只会被纵向拉伸

    self.zoomImageView.contentMode = UIViewContentModeScaleAspectFill;

    [self.tableView addSubview:self.zoomImageView];


4. 相关协议方法

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

   //根据实际选择加不加上NavigationBarHeigth

    CGFloat y = scrollView.contentOffset.y;

   if(y <  -ImageHight){

       CGRect frame=self.zoomImageView.frame;

       frame.origin.y=y;

       frame.size.height=-y;

        self.zoomImageView.frame=frame;

   }

}

#pragma mark - TableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return1;

}


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

    return20;

}

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

    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"SharkTop"];

    if(cell==nil){

        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:@"SharkTop"];

        cell.selectionStyle =UITableViewCellSelectionStyleNone;

        cell.separatorInset=UIEdgeInsetsZero;

        cell.clipsToBounds =YES;

    }

    cell.textLabel.text = [NSString stringWithFormat:@"%ld",indexPath.row];

    return cell;

}





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值