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

    function isURL(str_url) { var strRegex = "^((https|http|ftp|rtsp|mms)?://)" + "?(([0- ...

  2. Selenium2+python自动化20-Excel数据参数化

    前言 问: Python 获取到Excel一列值后怎么用selenium录制的脚本中参数化,比如对登录用户名和密码如何做参数化? 答:可以使用xlrd读取Excel的内容进行参数化.当然为了便于各位小 ...

  3. R--相关分布函数、统计函数的使用

    分布函数家族: *func()r : 随机分布函数d : 概率密度函数p : 累积分布函数q : 分位数函数 func()表示具体的名称如下表: 例子 #r : 随机分布函数 #d : 概率密度函数 ...

  4. Andorid开发学习---ubuntu 12.04下搭建超好用的安卓模拟器genymotion 安装卸载virtualbox 4.3

    什么是Genymotion? Genymotion是一套完整的工具,它提供了Android虚拟环境.它简直就是开发者.测试人员.推销者甚至是游戏玩家的福音. Genymotion支持Windows.L ...

  5. Photoshop 使用曲线

    曲线表示的是图像的明度, 通过信息办的 HSB 信息可以看到调整曲线时整个图像明度的变化 曲线的左下角表示图片的暗部, 右下角表示图片的高光部 而曲线本身的纵坐标则表示这个部分的明度, 例如将曲线的左 ...

  6. css文本属性

    CSS1&2中的文本属性 属性 版本 简介 text-indent CSS1 检索或设置对象中的文本的缩进 letter-spacing CSS1 检索或设置对象中的文字之间的间隔 word- ...

  7. Spring+MyBatis多数据源配置实现

    最近用到了MyBatis配置多数据源,原以为简单配置下就行了,实际操作后发现还是要费些事的,这里记录下,以作备忘 不多废话,直接上代码,后面会有简单的实现介绍 jdbc和log4j的配置 #定义输出格 ...

  8. checkbox和radio使用

    jQuery获取Radio选择的Value值: jQuery   C#   VB   C++   Java jQuery设置Radio的Value值: 语法解释: 1. $("input[n ...

  9. nodejs+express使用html和jade

    nodejs+express经常会看到使用jade视图引擎,但是有些人想要访问普通的html页面,这也是可以的: var express = require('express'); var port ...

  10. strace 监控所有php-fpm worker

    strace命令详解  http://linux.die.net/man/1/strace strace -tt -T $(pidof 'php-fpm: pool www' | sed 's/\([ ...