iOS开发-UITableView顶部图片下拉放大
关于顶部图片下拉放大,在用户展示的个人中心显示用户个人头像信息,设置UITableView的headerView实现,UITableView继承自UIScrollView,同样的设置UIScrollView的顶部图片也可以实现同样的效果,简单看一下实现的效果:
控制器中设置需要的属性变量:
@property (strong,nonatomic) UITableView *tableView;
@property (strong,nonatomic) NSArray *data;
@property (strong,nonatomic) UIView *tableHeaderView;
@property (strong,nonatomic) UIImageView *imageView;
初始化属性:
-(UITableView *)tableView{
if (!_tableView) {
_tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, 0,SCREENWIDTH, SCREENHEIGHT)];
_tableView.delegate=self;
_tableView.dataSource=self;
_tableView.showsVerticalScrollIndicator=NO;
_tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
[_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:CellIdetifier];
}
return _tableView;
}
-(UIView *)tableHeaderView{
if (!_tableHeaderView) {
_tableHeaderView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0,SCREENWIDTH, 100)];
}
return _tableHeaderView;
}
-(UIImageView *)imageView{
if (!_imageView) {
_imageView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 100)];
_imageView.autoresizingMask=UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
_imageView.clipsToBounds=YES;
_imageView.contentMode=UIViewContentModeScaleAspectFill;
}
return _imageView;
}
UITableViewDelegate实现:
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.data count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdetifier];
[cell.textLabel setText:self.data[indexPath.row]];
return cell;
}
ViewDidLoad中初始化imageView:
self.data=@[@"FlyElephant",@"博客园",@"UITableView图片放大",@"http://www.cnblogs.com/xiaofeixiang/"];
self.imageView.image=[UIImage imageNamed:@"Girl"];
self.imageView.contentMode=UIViewContentModeScaleAspectFill;
[self.tableHeaderView addSubview:self.imageView];
self.tableView.tableHeaderView=self.tableHeaderView;
[self.view addSubview:self.tableView];
在UITableViewView向下拉动的过程中,改变imageView的位置:
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
CGPoint offset = scrollView.contentOffset;
if (offset.y < 0) {
CGRect rect =self.tableHeaderView.frame;
rect.origin.y = offset.y;
rect.size.height =CGRectGetHeight(rect)-offset.y;
self.imageView.frame = rect;
self.tableHeaderView.clipsToBounds=NO;
}
}
实现起来比较简单,希望对有需要的人有所帮助~
iOS开发-UITableView顶部图片下拉放大的更多相关文章
- iOS开发 XML解析和下拉刷新,上拉加载更多
iOS开发 XML解析和下拉刷新,上拉加载更多 1.XML格式 <?xml version="1.0" encoding="utf-8" ?> 表示 ...
- 两种图片下拉放大效果实现(自定义CoordinatorLayout以及自定义Recylerview)
一.自定义CoordinatorLayout实现图片放大功能 本文是基于折叠布局实现的图片上拉滑动,下拉图片放大,松手放大的效果,先看下效果图. 实现原理: 1.使用CoordinatorLayout ...
- iOS开发 tableView点击下拉扩展 + 内嵌collectionView上传图片效果
---恢复内容开始--- //需要的效果 1.设置window的根视图控制器为一个UITableViewController #import "AppDelegate.h"#imp ...
- 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
- ios position:fixed 上滑下拉抖动
ios position:fixed 上滑下拉抖动 最近呢遇到一个ios的兼容问题,界面是需要一个头底部的固定的效果,用的position:fixed定位布局,写完测试发现安卓手机正常的,按时ios上 ...
- AJ学IOS 之tableView的下拉放大图片的方法
AJ分享,必须精品 一:效果 tableview下拉的时候上部分图片放大会 二:代码 直接上代码,自己研究吧 #import "NYViewController.h" //图片的高 ...
随机推荐
- winform调用浏览器
方法1: private void button1_Click(object sender, EventArgs e) .{ . //从注册表中读取默认浏览器可执行文件路径 . RegistryKey ...
- JSON.parse()和JSON.stringify()(转载)
parse用于从一个字符串中解析出json对象,如 var str = '{"name":"huangxiaojian","age":&qu ...
- TFS与Eclipse、Microsoft Visual Studio等客户端以webservice进行交换。
TFS与eclipse.Microsoft Visual Studio等客户端以webservice进行交互. 参考地址: http://server_ip:8080/tfs/项目区域/version ...
- static关键字用法
java中static关键字可用于修饰: 1.属性:表示该属性变量在类被加载时即被创建并初始化,类加载过程只进行一次,因此静态变量也只被创建一次 2.方法:静态方法为类的公有方法,可直接用‘类名.方法 ...
- [DiocpRPC]介绍与安装
介绍: Diocp-RPC组件基于DIOCP进行扩展开发,通信协议基于HTTP,遵循RESTFul开发模式,可以用户三层开发.IDE可以支持大于等于D7的IDE,服务端组件支持Win32/Win ...
- 权限<九>
介绍 角色就是相关权限的命令集合,使用角色的主要目的就是为了简化权限的管理,假定有用户 a,b,c 为了让他们都拥有权限 1. 连接数据库 2. 在 scott.emp 表上 select,ins ...
- Memcache学习php完整一例
header("Content-Type:text/html;charset=utf-8"); /* PHP设置分布式memcache存取 */ //创建memcache对象 $m ...
- oracle学习
在平时的工作学习中,经常需要使用到oracle数据库,将平时用到的一些技巧记录在这里,以便以后随时可以翻阅. 1.日期类型的比较 插入日期时,经常会使用sysdate来插入数据,但sysdate插入的 ...
- opencv学习_15 (利用cmake查看opencv的源码)
当我们有时想查看opencv自带的函数的源代码,比如函数cvCreateImage, 此时我们选中cvCreateImage, 点击鼠标右键->转到定义,我们会很惊讶的发现为什么只看到了cvCr ...
- Git创建 项目
一 . github上创建立一个项目 用户登录后系统,在github首页,点击页面右下角“New Repository” 填写项目信息: project name: hibernate-demo d ...