核心代码:

-(void)createTableViewHeaderView{

    _tableViewHeaderView = [[UIView alloc] initWithFrame:(CGRectMake(, , ScreenWidth, _imageHeight))];
_headerBackView = [[UIImageView alloc] init]; // 背景图
_headerBackView.frame = CGRectMake(, , ScreenWidth, _imageHeight);
_headerBackView.image = [UIImage imageNamed:@"bj1@2x.jpg"]; [_tableViewHeaderView addSubview:_headerBackView];
_photoImageView = [[UIImageView alloc] initWithFrame:CGRectMake((ScreenWidth - )/, , , )];
[self.tableViewHeaderView addSubview:self.photoImageView];
_photoImageView.layer.cornerRadius = ;
_photoImageView.layer.masksToBounds = YES; _photoImageView.image = [UIImage imageNamed:@"2.jpg"]; _userNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(, _photoImageView.frame.origin.y + _photoImageView.frame.size.height + , ScreenWidth, )];
_userNameLabel.font = [UIFont fontWithName:@"iconfont" size: ];
_userNameLabel.text = @"纳兰性德";
_userNameLabel.textAlignment = ;
_userNameLabel.font = [UIFont systemFontOfSize: ];
_userNameLabel.textColor = [UIColor whiteColor];
[_tableViewHeaderView addSubview:self.userNameLabel]; _introduceLabel = [[UILabel alloc] initWithFrame:CGRectMake((ScreenWidth - )/, _userNameLabel.frame.origin.y + _userNameLabel.frame.size.height + , , )];
_introduceLabel.alpha = .;
_introduceLabel.text = @"人生若只如初见,何事秋风悲画扇";
_introduceLabel.textAlignment = ;
_introduceLabel.font = [UIFont systemFontOfSize: ];
_introduceLabel.textColor = _userNameLabel.textColor;
[_tableViewHeaderView addSubview:self.introduceLabel]; self.tableView.tableHeaderView = _tableViewHeaderView; }
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{ CGFloat width = self.view.frame.size.width; // 图片宽度
CGFloat yOffset = scrollView.contentOffset.y; // 偏移的y值
if (yOffset < ) {
CGFloat totalOffset = _imageHeight + ABS(yOffset);
CGFloat f = totalOffset / _imageHeight;
self.headerBackView.frame = CGRectMake(- (width * f - width) / , yOffset, width * f, totalOffset); //拉伸后的图片的frame应该是同比例缩放。
} }

第十一篇、UITableView headerview下拉放大的更多相关文章

  1. iOS开发-UITableView顶部图片下拉放大

    关于顶部图片下拉放大,在用户展示的个人中心显示用户个人头像信息,设置UITableView的headerView实现,UITableView继承自UIScrollView,同样的设置UIScrollV ...

  2. IOS下拉放大图片

    代码地址如下:http://www.demodashi.com/demo/11623.html 一.实现效果图 现在越来越多的APP中存在下拉放大图片的效果,今天贡献一下我的实现这种方法的原理,和我遇 ...

  3. iOS实现下拉放大的功能

    #import "HMViewController.h" ; @interface HMViewController () @property (nonatomic, weak) ...

  4. android一个下拉放大库bug的解决过程及思考

    android一个下拉放大库bug的解决过程及思考 起因 项目中要做一个下拉缩放图片的效果,搜索了下github上面,找到了两个方案. https://github.com/Frank-Zhu/Pul ...

  5. [RN] React Native 下拉放大动画

    React Native 下拉放大动画 经测试,无法运行 https://www.jianshu.com/p/1c960ad75020

  6. UItableView UIcollectionView下拉刷新会跳动?看了此篇就能解决这个Bug了

    顺序如下:   1.数组添加:   for (id model in modellist.list) {     IDSCommentWeplayList *commentListModel = [I ...

  7. UITableView:下拉刷新和上拉加载更多

    [转载请注明出处] 本文将说明让UIScrollView支持"下拉刷新"和"上拉加载更多"的实现机制,并实现一个可用的tableView子类,以下主要以&quo ...

  8. AJ学IOS 之tableView的下拉放大图片的方法

    AJ分享,必须精品 一:效果 tableview下拉的时候上部分图片放大会 二:代码 直接上代码,自己研究吧 #import "NYViewController.h" //图片的高 ...

  9. IOS怎么实现一个UITableView的下拉刷新

    採用的EGORefreshTableHeaderView来实现: 在Controller上实现EGORefreshTableHeaderDelegate的delegate @property(nona ...

随机推荐

  1. input 上传文件的判断

    <html> <head> <meta charset='utf-8'> <meta name="viewport" content=&q ...

  2. JMeter - 如何在多个测试环境中运行多个线程组

    概述: 作为性能测试的一部分,我不得不为我们的应用程序提供各种用例/业务工作流程的性能测试脚本.当我设计我的性能测试脚本时,我将确保我有本文中提到的可重用测试脚本. JMeter - 如何创建可重用和 ...

  3. linux中的三种时间

    mtime [修改时间] 文件/目录的修改时间 ctime  [属性修改时间] 文件目录的属性的修改时间 atime  [访问时间]文件/目录的访问时间 stat 123.txt   File: `1 ...

  4. python入门之socket代码练习

    Part.1 简单的socket单次数据传输 服务端: #服务器端 import socket server = socket.socket() # 声明socket类型,同时生成socket连接对象 ...

  5. Python3.5 控制台日志输出,区分标准输出与错误输出

    import logging import sys class ConsoleHandler(logging.Handler): terminator = '\n' def __init__(self ...

  6. Maven的学习资料收集--(二)安装m2eclipse插件

    在Eclipse中可以安装Maven插件,可以更方便的使用: 官网地址:http://www.eclipse.org/m2e/ 可以在线安装或者离线下载,之前在线安装总是失败,可能是网速的原因,找到了 ...

  7. HAProxy负载均衡安装配置

    1.下载HAProxy    http://haproxy.1wt.eu/download/1.4/src/haproxy-1.4.22.tar.gz   2. 安装haproxy    #tar z ...

  8. codevs 1664 清凉冷水

    1664 清凉冷水 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold         题目描述 Description 闷热的夏天,威斯康辛州的奶制品地区提供冷水供奶牛 ...

  9. python2和3的区别丶网络编程以及socketserver多线程

    一丶python2和python3的区别 1.编码&字符串 字符串: python2: Unicode v = u"root"  本质上用unicode存储(万国码) (s ...

  10. 一个简单的EventEmitter

    用JS写了一个简单的EventEmitter: class EventEmitter { /** * 事件名/回调列表 字典 * @type {Map<string, Array<func ...