关于顶部图片下拉放大,在用户展示的个人中心显示用户个人头像信息,设置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顶部图片下拉放大的更多相关文章

  1. iOS开发 XML解析和下拉刷新,上拉加载更多

    iOS开发 XML解析和下拉刷新,上拉加载更多 1.XML格式 <?xml version="1.0" encoding="utf-8" ?> 表示 ...

  2. 两种图片下拉放大效果实现(自定义CoordinatorLayout以及自定义Recylerview)

    一.自定义CoordinatorLayout实现图片放大功能 本文是基于折叠布局实现的图片上拉滑动,下拉图片放大,松手放大的效果,先看下效果图. 实现原理: 1.使用CoordinatorLayout ...

  3. iOS开发 tableView点击下拉扩展 + 内嵌collectionView上传图片效果

    ---恢复内容开始--- //需要的效果 1.设置window的根视图控制器为一个UITableViewController #import "AppDelegate.h"#imp ...

  4. IOS下拉放大图片

    代码地址如下:http://www.demodashi.com/demo/11623.html 一.实现效果图 现在越来越多的APP中存在下拉放大图片的效果,今天贡献一下我的实现这种方法的原理,和我遇 ...

  5. iOS实现下拉放大的功能

    #import "HMViewController.h" ; @interface HMViewController () @property (nonatomic, weak) ...

  6. android一个下拉放大库bug的解决过程及思考

    android一个下拉放大库bug的解决过程及思考 起因 项目中要做一个下拉缩放图片的效果,搜索了下github上面,找到了两个方案. https://github.com/Frank-Zhu/Pul ...

  7. [RN] React Native 下拉放大动画

    React Native 下拉放大动画 经测试,无法运行 https://www.jianshu.com/p/1c960ad75020

  8. ios position:fixed 上滑下拉抖动

    ios position:fixed 上滑下拉抖动 最近呢遇到一个ios的兼容问题,界面是需要一个头底部的固定的效果,用的position:fixed定位布局,写完测试发现安卓手机正常的,按时ios上 ...

  9. AJ学IOS 之tableView的下拉放大图片的方法

    AJ分享,必须精品 一:效果 tableview下拉的时候上部分图片放大会 二:代码 直接上代码,自己研究吧 #import "NYViewController.h" //图片的高 ...

随机推荐

  1. Intellij Idea使用技巧、快捷键

    1.Idea设置字体大小:file -> setting -> editor -> colors&font -> save as并自定义 -> font -> ...

  2. 問題排查:行動裝置網頁前端 UI 設計 (1)

    這是最近開始接手的一個微信公眾平台專案, 在重整後端程式碼時,因為也需要透過前端來看效果, 所以就因此在前端的部分遇到了不少問題, 畢竟這是以前沒接觸過的領域 (早年的網頁應用程式開發沒有那麼多分工) ...

  3. php基础-转义字符

    1.php是弱类型语言,定义变量时无需要定义 2.标量类型:整形.浮点型.字符串类型.布尔型 复合类型:数组.对象 其它类型:资源类型(resource如数据库连接,打开文件句柄,资源在不需要时都要释 ...

  4. linux上配置网络/安装vsftp服务器

    1 准备用yum方式安装,小红帽linux原版不注册无法适用,只好安装centos系统 2 安装好centos系统注意事项: 硬盘得是IDE 配置好网络必须通,eth0的配置文件设置一下,联网启用 c ...

  5. 2016/10/28 很久没更了 leetcode解题 3sum

    15. 3Sum Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Fi ...

  6. upgrade-php-5-1-to-php-5-3-using-yum-on-centos

    wget -q -O - http://www.atomicorp.com/installers/atomic | shyum upgrade phpyum -y remove atomic-rele ...

  7. 一个使用方便的对FMDB进行封装的框架和一个可以切应用图标的应用

    框架的git地址 :https://github.com/Joker-King/JKDBModel 切割图标的应用地址 http://pan.baidu.com/s/1kVjflwr

  8. 1201新课程TSQL语句

    1.创建数据库 create datebase 表名称 2.删除数据库 drop datebase 表名称 3.创建表 -create table test(表名称)( code(列名称) varch ...

  9. iOS报错笔记

    问题一: linker command failed with exit code 1 (use -vto see invocation) 原因:导入了.m的头文件,导致同时有两个一样的.m文件在编译 ...

  10. linux用户、组管理及权限(一)

    一.用户管理 1.为什么需要用户 1)计算机及网络资源的合理分配  2)可以控制用户访问系统的权限.3)身份认证 4) 进程 以某个用户的身份来运行 2.用户分类 用户的角色是通过UID(用户ID)来 ...