第十一篇、UITableView headerview下拉放大
核心代码:
-(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下拉放大的更多相关文章
- iOS开发-UITableView顶部图片下拉放大
关于顶部图片下拉放大,在用户展示的个人中心显示用户个人头像信息,设置UITableView的headerView实现,UITableView继承自UIScrollView,同样的设置UIScrollV ...
- IOS下拉放大图片
代码地址如下:http://www.demodashi.com/demo/11623.html 一.实现效果图 现在越来越多的APP中存在下拉放大图片的效果,今天贡献一下我的实现这种方法的原理,和我遇 ...
- iOS实现下拉放大的功能
#import "HMViewController.h" ; @interface HMViewController () @property (nonatomic, weak) ...
- android一个下拉放大库bug的解决过程及思考
android一个下拉放大库bug的解决过程及思考 起因 项目中要做一个下拉缩放图片的效果,搜索了下github上面,找到了两个方案. https://github.com/Frank-Zhu/Pul ...
- [RN] React Native 下拉放大动画
React Native 下拉放大动画 经测试,无法运行 https://www.jianshu.com/p/1c960ad75020
- UItableView UIcollectionView下拉刷新会跳动?看了此篇就能解决这个Bug了
顺序如下: 1.数组添加: for (id model in modellist.list) { IDSCommentWeplayList *commentListModel = [I ...
- UITableView:下拉刷新和上拉加载更多
[转载请注明出处] 本文将说明让UIScrollView支持"下拉刷新"和"上拉加载更多"的实现机制,并实现一个可用的tableView子类,以下主要以&quo ...
- AJ学IOS 之tableView的下拉放大图片的方法
AJ分享,必须精品 一:效果 tableview下拉的时候上部分图片放大会 二:代码 直接上代码,自己研究吧 #import "NYViewController.h" //图片的高 ...
- IOS怎么实现一个UITableView的下拉刷新
採用的EGORefreshTableHeaderView来实现: 在Controller上实现EGORefreshTableHeaderDelegate的delegate @property(nona ...
随机推荐
- idea dao使用@Mapper注解 业务类使用@Autowired 注入dao 爆红问题
实际项目跑起来无影响,但是看起来不太爽. 可以在dao类添加org.springframework.stereotype.Repository 注解 或者可以在service类中使用 javax.an ...
- Java start和run启动线程的区别
我们知道,我们通过调用线程的start方法启动一个线程,那么,我们可以直接调用run方法来启动一个线程吗? 先看下面一段代码: public class Test { public static vo ...
- CSS之flex兼容
我觉得写的很好的文章,但是我又没有时间去整理的. https://blog.csdn.net/u010130282/article/details/52627661 百分比 是在宽度自适应的时候要用 ...
- List<Object> 使用Linq
List<Asset> bdList = allAsset.Where(m => m.Owner.Depts == view.DeptName).ToList(); var quer ...
- rabbitMq解析
import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import java.util ...
- jquery $.fn $.fx 的意思以及使用
$.fn是指jquery的命名空间,加上fn上的方法及属性,会对jquery实例每一个有效,下面简单为大家介绍下jquery $.fn $.fx到底是怎么一回事 $.fn是指jquery的命名空间,加 ...
- python入门之socket代码练习
Part.1 简单的socket单次数据传输 服务端: #服务器端 import socket server = socket.socket() # 声明socket类型,同时生成socket连接对象 ...
- 成功安装tesserocr
首先按照官网的操作,出现了下面的错误. 错误描述: x86_64-linux-gnu-gcc: error trying to exec 'cc1plus': execvp: 没有那个文件或目录 er ...
- Unity [Tooltip("")]
把Ad2Controller脚本挂在Ad2Ad3Manager游戏对象上,在非运行状态下把鼠标放在inspector的AdButtonObj2上就会显示广告2按钮. 如下图:
- php面试题分享
1.nginx使用哪种网络协议? nginx是应用层 我觉得从下往上的话 传输层用的是tcp/ip 应用层用的是http fastcgi负责调度进程 2. <? echo 'hello tush ...