第十一篇、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 ...
随机推荐
- java动态线程池LinkedBlockingQueue和SynchronousQueue比较
import java.util.concurrent.Callable; public class MyCallable implements Callable<String> { pr ...
- wms-springmvc-servlet.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- learn_tmp
// 4.1构造映射val scores = Map("Alice" -> 10, "Bob" -> 3, "Cindy" -& ...
- 练习九:time.sleep方法
让python程序暂停预定时间后再运行,需要用到time.sleep方法要求,随便写入一段代码,测试time.sleep方法 import time dict1 = {1:'a',2:'b',3:'c ...
- sql新增字段注意事项
新增字段的类型.长度(精度)是否合适 解决方法: 跟应用明确加字段和改字段的风险,确认新增字段类型正确.长度(精度)合适. 以及跟应用明确老数据是否要订正?如何订正?新增列是否非空?是否有默认值等等. ...
- View转换为Bitmap及getDrawingCache
View组件显示的内容可以通过cache机制保存为bitmap, 使用到的api有 void setDrawingCacheEnabled(boolean flag), Bitmap get ...
- 四则运算 calc()
它的出现还真的蛮令人惊喜的,很适用于百分比宽度.之前我们有box-sizng,而今又多了一个它,并且,calc的实用性更高.我们可以在border.margin.pading.font-size和wi ...
- 三,JVM 自带命令行工具之JMap
jmap:java内存映像工具 jmap(Memory Map for java ) 命令用于生成堆转储快照(一般被称为headdump 或dump文件) jmap命令格式:jmap [option ...
- MongoDB Linux 安装配置 后台运行
介绍安装的文档很多,可以参考这篇: http://www.mkyong.com/mongodb/how-to-install-mongodb-on-mac-os-x/ 安装完后你可能会碰到的2个问题. ...
- ElasticSearch入门-搜索(java api)
ElasticSearch入门-搜索(java api) package com.qlyd.searchhelper; import java.util.Map; import net.sf.json ...