UITableview顶部视图缩放效果

来源:互联网 发布:环境大数据研究中心 编辑:程序博客网 时间:2024/06/07 05:02
- (void)viewDidLoad{    [super viewDidLoad];    // 创建tableView header view    UIView *headerBackView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, self.view.frame.size.width, 180)];    _tableView.tableHeaderView = headerBackView;     // 创建imageView    imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 180)];    imageView.image =[UIImage imageNamed:@"imagePic"];    imageView.contentMode = UIViewContentModeScaleAspectFit;    imageView.clipsToBounds = true;    [headerBackView addSubview:imageView];}#pragma mark - scrollView delegate- (void)scrollViewDidScroll:(UIScrollView *)scrollView{    CGFloat width = self.view.frame.size.width;     //图片宽度    CGFloat yOffSet = scrollView.contentOffset.y;   //偏移量    if (yOffSet < 0) { //表示向下滑动        CGFloat totalOffset = 180 + fabs(yOffSet);        CGFloat f = totalOffset / 180; //缩放系数        imageView.frame = CGRectMake(-(f * width - width)/2, yOffSet, width * f, totalOffset);    }}


                                             
0 0