您的位置:首页 > 产品设计 > UI/UE

TableView头部图片下拉图片放大

2016-09-06 18:10 381 查看
浏览商品时,组头放置的商品图片,下拉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.contentInset = UIEdgeInsetsMake(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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息