例如探探个人信息界面拉伸效果,下拉头像放大

//
//  PersonController.m
//  Spread
//
//  Created by qiuxuewei on 16/3/21.
//  Copyright © 2016年 邱学伟. All rights reserved.
//#import "PersonController.h"@interface PersonController ()<UITableViewDataSource, UITableViewDelegate, UIScrollViewDelegate>{}//属性列表
/** 顶部图片视图 */
@property (nonatomic, strong) UIImageView *headerImageView;
@property (nonatomic, strong) UIView *headerBackView;
/** 个人信息界面 */
@property (nonatomic, strong) UITableView *tableView;@end@implementation PersonController
#pragma mark - 懒加载
-(UIView *)headerBackView{if (_headerBackView == nil) {_headerBackView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 200)];[_headerBackView setBackgroundColor:[UIColor lightGrayColor]];}return _headerBackView;
}
-(UIImageView *)headerImageView{if (_headerImageView == nil) {_headerImageView = [[UIImageView alloc] init];[_headerImageView setImage:[UIImage imageNamed:@"邱_生活.JPG"]];[_headerImageView setBackgroundColor:[UIColor greenColor]];[_headerImageView setContentMode:UIViewContentModeScaleAspectFill];[_headerImageView setClipsToBounds:YES];}return _headerImageView;
}
-(UITableView *)tableView{if (_tableView == nil) {_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) style:UITableViewStyleGrouped];[_tableView setDataSource:self];[_tableView setDelegate:self];}return _tableView;
}- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view from its nib.//添加子视图[self addChildViews];
}
#pragma mark - 类内方法
//添加子视图
-(void)addChildViews{//添加表格[self.view addSubview:self.tableView];//添加头像图片[self addHeaderImageView];
}
//添加头像
-(void)addHeaderImageView{[self.tableView setTableHeaderView:self.headerBackView];[self.headerImageView setFrame:self.headerBackView.bounds];[self.headerBackView addSubview:self.headerImageView];
}#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{return 4;
}-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{return 2;
}-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{return 64;
}-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{// 不加此句时,在二级栏目点击返回时,此行会由选中状态慢慢变成非选中状态。// 加上此句,返回时直接就是非选中状态。[tableView deselectRowAtIndexPath:indexPath animated:YES];
}//初始化cell
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{static NSString *ID = @"cell";UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];if (!cell) {cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];}//初始化cell数据![cell.textLabel setText:@"阿伟"];[cell.detailTextLabel setText:@"2016-03-22"];return cell;
}//滚动tableview 完毕之后
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{//图片高度CGFloat imageHeight = self.headerBackView.frame.size.height;//图片宽度CGFloat imageWidth = kScreenWidth;//图片上下偏移量CGFloat imageOffsetY = scrollView.contentOffset.y;NSLog(@"图片上下偏移量 imageOffsetY:%f ->",imageOffsetY);//上移if (imageOffsetY < 0) {CGFloat totalOffset = imageHeight + ABS(imageOffsetY);CGFloat f = totalOffset / imageHeight;self.headerImageView.frame = CGRectMake(-(imageWidth * f - imageWidth) * 0.5, imageOffsetY, imageWidth * f, totalOffset);}//    //下移
//    if (imageOffsetY > 0) {//        CGFloat totalOffset = imageHeight - ABS(imageOffsetY);
//        CGFloat f = totalOffset / imageHeight;
//
//        [self.headerImageView setFrame:CGRectMake(-(imageWidth * f - imageWidth) * 0.5, imageOffsetY, imageWidth * f, totalOffset)];
//    }}- (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated.
}/*
#pragma mark - Navigation// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {// Get the new view controller using [segue destinationViewController].// Pass the selected object to the new view controller.
}
*/@end

iOS-tableview顶部拉伸效果(头像拉伸)相关推荐

  1. ios实践之tableView顶部“弹簧”图片

    大家可能注意到有些tableView的顶部图片,会随着你拉伸而跟着拉伸变大. 一种思路是将图片放置tableView的tableHeaderView上当tablview下移改变图片的frame达到效果 ...

  2. 导航栏透明度渐变; 下拉头视图拉伸效果;勾号动画; 一段文字中点击部分可响应不同事件...

    之前通过设置navigationBar的barTintColor设置导航栏颜色,然后拿到self.navigationController.navigationBar.subviews.firstOb ...

  3. CSS3动画 - title下划线的拉伸效果

    类似于 加载条 1. 效果图 2. 代码 <!DOCTYPE html> <html> <head> <meta charset="UTF-8&qu ...

  4. android 图片拉伸动画,java,Android_Android的属性动画的拉伸效果前后两次效果不一致,求解?,java,Android - phpStudy...

    Android的属性动画的拉伸效果前后两次效果不一致,求解? 开发过程中需要做五个点的上下拉伸效果,奇怪的是第一次进行拉伸的时候是正常的,但是第二次开始就不对了,加打印看也没问题啊,实在是找不到原因, ...

  5. Flutter Row 或者 Column 的拉伸效果,CrossAxisAlignment.stretch

    CrossAxisAlignment.stretch 不生效? Flutter 版本:2.5.1 布局代码如下,加 Container 是为了设置个背景颜色,看效果,单独使用 Row 也一样: Ele ...

  6. Vue自定义指令实现弹窗拖拽,四边拉伸及对角线拉伸

    Vue自定义指令实现弹窗拖拽,四边拉伸及对角线拉伸 引言 页面布局 drag.js文件 弹窗拖拽实现及边界限制 鼠标指针悬停样式 四边拉伸及对角线拉伸 拉伸干涉 引言 近期公司vue前端项目需求:实现 ...

  7. iOS TableView多级列表

    代码地址如下: http://www.demodashi.com/demo/15006.html 效果预览 一.需求 TableView多级列表:分级展开或合并,逐级获取并展示其子级数据,可以设置最大 ...

  8. 中img拉伸_8个拉伸动作,帮你调动全身肌肉,提高柔韧性,缓解疲劳放松心情...

    拉伸,是一种被大众所了解却不怎么被认可的一项运动形式,之所以被大众所了解是因为拉伸这项运动对于没有什么运动经验的人群来讲都是不陌生的.而不怎么被认因为在运动过程中拉伸这项运动却经常被我们刻意地忽视,或 ...

  9. iOS TableView 使用详解

     IOS TableView 详解 一.建立 UITableView DataTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ...

最新文章

  1. 使用VS自带的混淆器防止你的程序被反编译
  2. hadoop java client_hadoop3 Java client客户端kerberos认证
  3. LOJ#510. 「LibreOJ NOI Round #1」北校门外的回忆(线段树)
  4. leetcode 刷题之路 64 Construct Binary Tree from Inorder and Postorder Traversal
  5. hdu 1867 求两个串的和最小 ,KMP
  6. Leetcode每日必刷题库第80题,如何在不使用外部空间的情况下对有序数组去重?
  7. zcmu-2153(拓扑排序+优先队列)
  8. java使用的页面静态化技术_java秒杀系列(2)- 页面静态化技术
  9. 澳网:公茂鑫/张择创历史 中国男网夺大满贯首胜
  10. 55寸鸿蒙安卓,深网|荣耀智慧屏发布:搭载鸿蒙系统 配55英寸屏3799元起
  11. 从一个故事开始谈项目与团队管理
  12. Webpack 实现 Tree shaking 的前世今生
  13. VBA中让程序休眠 SLeep的方法
  14. 《深入浅出统计学》笔记
  15. Pycharm一直显示connecting to console
  16. 多场景双师课堂解决方案
  17. 2022款Thinkphp家政上门预约系统-全开源系统源码
  18. 【MicroPython ESP32】NVS数据非易失性存储示例讲解说明
  19. 肾囊肿的临床症状有哪些?
  20. 安卓WebView的那些坑

热门文章

  1. .net实现微信大转盘
  2. PCA主成分分析方法
  3. 2018同城货运行业分析报告
  4. html5画分形图形,HTML5/Canvas 可在线调整的朱丽叶分形图
  5. 长江大数据交易平台上线
  6. 怎么在Unity2019中烘焙lightmap
  7. c语言如何与plc串口通信,计算机与PLC直接通信
  8. 活动?创作两周年纪念日,浅记经验感想
  9. 洛谷(P1304 哥德巴赫猜想)
  10. 数字的英文表达和中文表达