效果图

开始简单的代码过程

其实思路很简单 就是 让tableView偏移 一图片的高度,然后在把图片添加到tableView中,然后再监听didScrollView,在里面改变图片的frame

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. self.automaticallyAdjustsScrollViewInsets = NO; _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, navH, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame) - navH) style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
/* 设置tableView的偏移量 **/
_tableView.contentInset = UIEdgeInsetsMake(startImageViewH, 0, 0, 0);
[self.view addSubview:_tableView]; /*
* 注意 imageView 的Y 值是-startImageViewH 其实这个值就是 tableView的内容偏移量
* 如果Y 是0的话它还是会跟着tableView偏移startImageViewH 值
**/
UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, -startImageViewH, CGRectGetWidth(self.view.frame), startImageViewH)];
imageView.image = [UIImage imageNamed:@"1"];
self.imageView = imageView;
[self.tableView addSubview:imageView]; } - (void)scrollViewDidScroll:(UIScrollView *)scrollView { CGFloat offsetY = scrollView.contentOffset.y;
NSLog(@"offsetY = %f",offsetY); /* 计算往下拉的时候偏移量 **/
if (offsetY < -startImageViewH) { /* 计算差值 **/
CGFloat interval = -CGRectGetHeight(self.imageView.frame) - offsetY; /* imageView 的高度 增加 interval **/
CGFloat imageViewH = CGRectGetHeight(self.imageView.frame) + interval;
/* 计算 imageView的 高度增加后的,宽度增加后的值 **/
CGFloat imageViewW = imageViewH*CGRectGetWidth(self.imageView.frame)/CGRectGetHeight(self.imageView.frame);
/* 计算 imageView X 的偏移量 **/
CGFloat imageViewX =self.imageView.frame.origin.x - (imageViewW -CGRectGetWidth(self.imageView.frame))/2;
/* 计算 imageView Y 的偏移量 **/
CGFloat imageViewY =self.imageView.frame.origin.y - interval;
/* 赋值 **/
self.imageView.frame = CGRectMake(imageViewX, imageViewY, imageViewW, imageViewH); } }

demo地址:https://github.com/lichory/pullDownImageView

本文借鉴简书作者李重阳_arc的文章,写在这里是为了在自己的博客里做一份备份。

最新文章

  1. GAMBIT、ICEM、HYPERMESH耦合面的处理方法
  2. dev checkbox多选
  3. C#打开一个文本文件并读写
  4. 提高 Linux 上 socket 性能
  5. 【Linux高频命令专题(15)】more
  6. C++ cout cerr 和 clog 的区别
  7. 2015第15周日PostgreSQL学习
  8. 73_leetcode_Construct Binary Tree from Inorder and Postorder Traversal
  9. asp.net MVC中使用Autofac小结 (遇到的最傻错误: 没有为该对象定义无参数的构造函数)
  10. js验证表单密码、用户名是否输入--JS的简单应用
  11. 再说php依赖注入
  12. Python 自学 之 String 常见操作
  13. Junit简单配置
  14. 关于JQuery中的ajax请求或者post请求的回调方法中的操作执行或者变量修改没反映的问题
  15. eclipse无法连接genymotion+Unable to start the Genymotion virtual device
  16. Numpy学习三:数组运算
  17. fork()、vfork()、clone()的区别
  18. ionic3 启动白屏处理
  19. day5 算数,比较,赋值,逻辑运算符,表达式
  20. SSH 项目整合

热门文章

  1. wareshark网络协议分析之DHCP
  2. ggplot笔记001——ggplot2安装
  3. js备忘录模式
  4. 一款简易的CSS3扁平化风格联系表单
  5. Memcache简介 &amp; 内存分配机制
  6. 表格表格中获取不到button选择器
  7. Left Join ,On Where
  8. tagclass,taglib,tld设置
  9. CTR点击率简介
  10. CentOS7下Tomcat启动特别慢【有效解决】