zoukankan      html  css  js  c++  java
  • iOS tableView下拉图片放大

    事实上这个效果,本质上就是在你tableView下拉 造成offset时候。 保持你顶部图片的y坐标点还停留在下拉时屏幕的顶点(offset), 而图片的长度变为原始的height长度-(offset ) 就达到了下拉放大的效果。

     直接上代码了:

                          1. 首先创建一个UIView作为headerView

                _topView = [[UIViewalloc]initWithFrame:CGRectMake(0,0,MCAPPWidth,80)];

                _tableView.tableHeaderView =_topView;

               2.其次创建一个UIImageView放那张图片 

                _topImageView = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0,MCAPPWidth,80)];

                _topImageView.contentMode =UIViewContentModeScaleAspectFill;

                _topImageView.layer.masksToBoundsYES;

                [_topImageViewsd_setImageWithURL:[NSURLURLWithString:nil]placeholderImage:[UIImageimageNamed:@"mian_bg"]];

                [_topViewaddSubview:_topImageView];


               3.最后引入scrollView的代理方法 监听frame的变化

                

    - (void)scrollViewDidScroll:(UIScrollView *)scrollView

    {

       if (_tableView == scrollView) {

         CGFloat yOffset = _tableView.contentOffset.y;

        //下拉图片放大

        if (yOffset < 0) {

            _topView.frame = CGRectMake(0, 0, MCAPPWidth80 * Height - yOffset);

            _topImageView.frame = CGRectMake(0, yOffset, MCAPPWidth80 * Height - yOffset);

            NSLog(@"%.2f"_topImageView.y);

        }

        else {

            _topView.frame = CGRectMake(00MCAPPWidth80 * Height - yOffset);

            _topImageView.y = yOffset * 0.65;

            _topImageView.height = 80 * Height - yOffset * 0.65;

        }

       }

    }

    我这里上拉 图片做的是相对位移 假设仅仅须要下拉变大效果 上拉回原样 须要把else 里的 后两句代码凝视掉, 换成_topImageView.y = _topView.y值保持一样就可以。

    我这里的.y是自己封装的方法直接copy会出错哦。

  • 相关阅读:
    单调栈
    单调队列
    线段树
    树状数组
    KMP模式匹配
    二分图最大匹配
    celery发送短信接口
    celery配置与基本使用
    celery介绍
    短信验证接口
  • 原文地址:https://www.cnblogs.com/brucemengbm/p/6752187.html
Copyright © 2011-2022 走看看