核心代码:

-(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. 手动添加git 到 右键菜单

    1.通过在“运行”中输入‘regedit’,打开注册表. 2.找到[HKEY_CLASSES_ROOT\Directory\Background]. 3.在[Background]下如果没有[shel ...

  2. noip2018复习计划啊

    需要复习的算法额: exgcd CRT INV dij spfa(~) 矩阵快速幂~高斯消元 tarjan(scc,bcc) treap splay 线段树 dp(决策单调,斜率,四边形不等式) rh ...

  3. Django - 权限(3)- 动态显示二级菜单

    一.动态显示二级菜单 上篇随笔中,我们实现了动态显示一级菜单,现在考虑这样一种情况,用户的菜单权限比较多,这个时候全部并列展现在左侧菜单就不合适了,所以,现在有这样一个需求,即把用户的菜单权限分类,划 ...

  4. 018 4Sum 四个数的和

    给定一个含有 n 个整数的数组 S,数列 S 中是否存在元素 a,b,c 和 d 使 a + b + c + d = target ?请在数组中找出所有满足各元素相加等于特定值的不重复组合.注意:解决 ...

  5. onCreateOptionsMenu

    onCreateOptionsMenu----只在Activity创建时调用一次!之后不会再被调用! onPrepareOptionsMenu----每次display menu之前,都會调用该方法, ...

  6. SPOJ 3267: DQUERY 树状数组,离线算法

    给出q个询问,询问一段区间里面的不同元素的个数有多少个. 离线做,用树状数组. 设树状数组的意义是:1--pos这个段区间的不用元素的种类数.怎么做?就是add(pos,1);在这个位置中+1,就是说 ...

  7. Unity (反向动力学)IK动画

  8. JavaFX上手--第1天

    1.第一个JavaFX Application JavaFX 使用Java来制作可视化图形,可以做动画和3D效果,JavaFX从JDK中直接使用. package application; impor ...

  9. Likely root cause: java.lang.IllegalStateException: jar hell!

    jar hell 解决方案: 问题: Likely root cause: java.lang.IllegalStateException: jar hell! 解决: 当一一个类或者一一个资源文件存 ...

  10. LitePal——安卓数据库library

    简介:一个让开发者使用SQLite数据库更加容易的库文件 LitePal for Android,项目地址:点击打开 LitePal是一个开源的android库,它让开发者使用SQLite数据变得容易 ...