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

    using System;using System.Collections;using System.Collections.Generic;using System.Data;using Syste ...

  2. Selenium2+python自动化3-解决pip使用异常

    一.pip出现异常 有一小部分童鞋在打开cmd输入pip后出现下面情况:Did not provide a commandDid not provide a command?这是什么鬼?正常情况应该是 ...

  3. CentOS7安装mysql5.7.11

    开始安装 yum update yum install wget wget http://repo.mysql.com/mysql57-community-release-el7-7.noarch.r ...

  4. 在Mac OS X中配置Apache

    启动Apache 有两种方法: 打开“系统设置偏好(System Preferences)” -> “共享(Sharing)” -> “Web共享(Web Sharing)” 打开“终端( ...

  5. Trie树:POJ2001

    这是一道最简单的trie树的题 有趣的是这道题的测试用例无法在VS上调试,只能在框框里不断提交测试了,哈哈 最基本的Trie树,插入和查找操作没什么好说的 注意节点添加一个count变量作为附加条件, ...

  6. CSS样式之语法

    选择符 选择符 {属性1:属性值1;属性2:属性值2} 选择符(selector):指定样式适用的标签,除指定标签外,样式不起作用 属性:样式的关键字 属性值:描述样式的值: 格式:属性与属性之间使用 ...

  7. Eclipse CDT、MingGW 遇到的一些错误汇总

    1.写代码时报错 "Member declaration not found" 如图: 在StackOverflow上找到的答案: 出问题的地方是 CDT的新功能 代码检查 Ope ...

  8. JQuery教程

    1.是javaScript库(js文件) 2.使用:script标签 3.语法:$开头 $().action() 列如:$('div').css("color",'red'); 4 ...

  9. jobs 命令

    jobs命令  显示了当前 shell 环境中已启动的作业状态. 如果 JobID 参数没有指定特定作业,就显示所有的活动的作业的状态信息. 如果报告了一个作业的终止,shell 从当前的 shell ...

  10. PHP中想过获取系统内置的所有常量吗?

    print_r(get_defined_constants(true)); OK!这样就可以了,赶紧去试试吧