美文网首页
ios UITableView头部带有图片并且下拉图片放大效果

ios UITableView头部带有图片并且下拉图片放大效果

作者: 尹时允 | 来源:发表于2017-07-27 09:16 被阅读0次

    一.位置确定

    img = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];

    img.image = [UIImage imageNamed:@"headerImage1.jpg"];

    UIView *v1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 200)];

    table.tableHeaderView = v1;

    [v1 addSubview:img];

    UIView *v2 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

    table.backgroundView = v2;

    [v2 addSubview:img];

    二.实现滑动效果

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

    CGRect tempRect = img.frame;

    if (scrollView.contentOffset.y > 0) {

    tempRect.origin.y = -scrollView.contentOffset.y;

    img.frame = tempRect;

    }else {

    tempRect.origin.y = 0;

    tempRect.size.height = 200 - scrollView.contentOffset.y;

    img.frame = tempRect;

    }

    相关文章

      网友评论

          本文标题:ios UITableView头部带有图片并且下拉图片放大效果

          本文链接:https://www.haomeiwen.com/subject/pqoizttx.html