核心代码:

-(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. Jmeter3.2源码编译环境搭建(转)

    1.下载jmeter3.2源码 https://github.com/apache/jmeter/tree/v3_2 https://blog.csdn.net/fly_to_higher/artic ...

  2. EcmaScript学习

    1.eval: ts: declare function eval(x: string): any; js: /** @param {*} x @return {Object} */ eval = f ...

  3. POJ2945 Find the Clones trie树

    建一颗$trie$树(当然你哈希也资瓷),边插边更新,看看搜到最底时有多少个字符串,然后更新. #include<cstdio> #include<iostream> #inc ...

  4. maven参数

    mvn clean package -DskipTests mvn -T 2 clean install/mvn -T 2C clean install: maven支持并行构建,-T 2表示使用2个 ...

  5. 014 Longest Common Prefix 查找字符串数组中最长的公共前缀字符串

    编写一个函数来查找字符串数组中最长的公共前缀字符串. 详见:https://leetcode.com/problems/longest-common-prefix/description/ 实现语言: ...

  6. Ubuntu14.04 查看安装的jetty的版本

    1.首先找到start.jar , Ubuntu14.04 在/usr/share/jetty 目录下, 2.然后运行 java -jar start.jar -- version 参考

  7. tcpdump安装配置及抓包分析

    http://blog.csdn.net/e421083458/article/details/23963189 cpdump安装配置及抓包分析 预装软件:[plain] view plain cop ...

  8. leetcoe--47. Permutations II

    1.问题描述 Given a collection of numbers that might contain duplicates, return all possible unique permu ...

  9. python3+Appium自动化01-Appium环境搭建

    环境依赖 Node.js Appium Appium-desktop Appium-doctor Appium-Python-Client Python JDK Android SDK 安装Node. ...

  10. zk小结

    一 ZooKeeper功能 1.文件系统 2.通知机制 二 Zookeeper文件系统 每个子目录项都被称作为znode,和文件系统一样,我们能够自由的增加.删除znode,在一个znode下增加.删 ...