UITableView的headerView展开缩放动画

效果

源码

https://github.com/YouXianMing/Animations

//
// HeaderViewTapAnimationController.m
// Animations
//
// Created by FrankLiu on 15/11/30.
// Copyright © 2015年 YouXianMing. All rights reserved.
// #import "HeaderViewTapAnimationController.h"
#import "ClassModel.h"
#import "StudentInfoCell.h"
#import "ClassHeaderView.h"
#import "WxHxD.h"
#import "GCD.h" static NSString *infoCellFlag = @"BaseTableViewCell";
static NSString *infoHeadFlag = @"ClassHeaderView"; @interface HeaderViewTapAnimationController () <UITableViewDataSource, UITableViewDelegate, CustomHeaderFooterViewDelegate> @property (nonatomic, strong) NSMutableArray *classModels;
@property (nonatomic, strong) UITableView *tableView; @property (nonatomic) BOOL sectionFirstLoad;
@property (nonatomic, weak) ClassHeaderView *tmpHeadView; @end @implementation HeaderViewTapAnimationController - (void)viewDidLoad { [super viewDidLoad];
} - (void)setup { [super setup]; [self createDatas]; [self createTableView]; [self bringTitleViewToFront]; [self firstLoadDataAnimation];
} #pragma mark - 数据源相关
- (void)createDatas { NSArray *datas = @[@{@"className" : @"Aitna",
@"students" : @[@{@"name" : @"Y.X.M.", @"age" : @()},
@{@"name" : @"Leif", @"age" : @()},
@{@"name" : @"Lennon", @"age" : @()},
@{@"name" : @"Lambert", @"age" : @()},
@{@"name" : @"Jerome", @"age" : @()},
@{@"name" : @"Isidore", @"age" : @()}]},
@{@"className" : @"Melete",
@"students" : @[@{@"name" : @"Merle", @"age" : @()},
@{@"name" : @"Paddy", @"age" : @()},
@{@"name" : @"Perry", @"age" : @()},
@{@"name" : @"Philip", @"age" : @()}]},
@{@"className" : @"Aoede",
@"students" : @[@{@"name" : @"Verne", @"age" : @()},
@{@"name" : @"Vincent", @"age" : @()},
@{@"name" : @"Walter", @"age" : @()},
@{@"name" : @"Zachary", @"age" : @()}]},
@{@"className" : @"Dione",
@"students" : @[@{@"name" : @"Timothy", @"age" : @()},
@{@"name" : @"Roderick", @"age" : @()},
@{@"name" : @"Quentin", @"age" : @()},
@{@"name" : @"Paddy", @"age" : @()}]},
@{@"className" : @"Adanos",
@"students" : @[@{@"name" : @"Mortimer", @"age" : @()},
@{@"name" : @"Michael", @"age" : @()},
@{@"name" : @"Kevin", @"age" : @()},
@{@"name" : @"Jeremy", @"age" : @()}]},]; self.classModels = [[NSMutableArray alloc] init];
for (int count = ; count < datas.count; count++) { ClassModel *classModel = [[ClassModel alloc] initWithDictionary:datas[count]];
classModel.expend = NO; [self.classModels addObject:classModel];
}
} #pragma mark - tableView相关
- (UITableView *)createTableViewWithDelegate:(id)delegate frame:(CGRect)frame { UITableView *tableView = [[UITableView alloc] initWithFrame:frame style:UITableViewStylePlain];
tableView.delegate = delegate;
tableView.dataSource = delegate;
tableView.separatorStyle = UITableViewCellSeparatorStyleNone; tableView.showsHorizontalScrollIndicator = NO;
tableView.showsVerticalScrollIndicator = NO; [tableView registerClass:[StudentInfoCell class] forCellReuseIdentifier:infoCellFlag];
[tableView registerClass:[ClassHeaderView class] forHeaderFooterViewReuseIdentifier:infoHeadFlag]; return tableView;
} - (void)createTableView { self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(, , Width, Height - ) style:UITableViewStylePlain];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.showsHorizontalScrollIndicator = NO;
self.tableView.showsVerticalScrollIndicator = NO; [self.tableView registerClass:[StudentInfoCell class] forCellReuseIdentifier:infoCellFlag];
[self.tableView registerClass:[ClassHeaderView class] forHeaderFooterViewReuseIdentifier:infoHeadFlag]; [self.view addSubview:self.tableView];
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { ClassModel *model = _classModels[section]; if (model.expend == YES) { return [model.students count]; } else { return ;
}
} - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { if (self.sectionFirstLoad == NO) { return ; } else { return [_classModels count];
}
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:infoCellFlag]; ClassModel *classModel = _classModels[indexPath.section];
StudentModel *studentModel = classModel.students[indexPath.row];
cell.data = studentModel;
cell.indexPath = indexPath;
[cell loadContent]; return cell;
} - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { ClassHeaderView *titleView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:infoHeadFlag];
titleView.delegate = self;
titleView.data = _classModels[section];
titleView.section = section;
[titleView loadContent]; if (section == ) { self.tmpHeadView = titleView;
} ClassModel *model = _classModels[section];
if (model.expend == YES) { [titleView extendStateAnimated:NO]; } else { [titleView normalStateAnimated:NO];
} return titleView;
} - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return ;
} - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return ;
} - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { StudentInfoCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[cell showSelectedAnimation]; [tableView deselectRowAtIndexPath:indexPath animated:YES];
} - (void)customHeaderFooterView:(CustomHeaderFooterView *)customHeaderFooterView event:(id)event { NSInteger section = customHeaderFooterView.section;
ClassModel *model = _classModels[section]; ClassHeaderView *classHeaderView = (ClassHeaderView *)customHeaderFooterView; if (model.expend == YES) { // 缩回去
model.expend = NO;
[classHeaderView normalStateAnimated:YES]; NSMutableArray *indexPaths = [NSMutableArray array];
for (int i = ; i < model.students.count; i++) { [indexPaths addObject:[NSIndexPath indexPathForItem:i inSection:section]];
}
[self.tableView deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade]; } else { // 显示出来
model.expend = YES;
[classHeaderView extendStateAnimated:YES]; NSMutableArray *indexPaths = [NSMutableArray array];
for (int i = ; i < model.students.count; i++) { [indexPaths addObject:[NSIndexPath indexPathForItem:i inSection:section]];
}
[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];
}
} - (void)firstLoadDataAnimation { [GCDQueue executeInMainQueue:^{ // Extend sections.
self.sectionFirstLoad = YES;
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(, self.classModels.count)];
[self.tableView insertSections:indexSet withRowAnimation:UITableViewRowAnimationFade]; [GCDQueue executeInMainQueue:^{ // Extend cells.
[self customHeaderFooterView:self.tmpHeadView event:nil]; } afterDelaySecs:0.4f]; } afterDelaySecs:0.3f];
} @end

细节

UITableView的headerView展开缩放动画的更多相关文章

  1. Swift - UITableView展开缩放动画

    Swift - UITableView展开缩放动画 效果 源码 https://github.com/YouXianMing/Swift-Animations // // HeaderViewTapA ...

  2. 仿Inshot分享页图片圆形展开缩放动画

    版权声明:本文为xing_star原创文章,转载请注明出处! 本文同步自http://javaexception.com/archives/221 圆形展开缩放动画 关键代码: final Anima ...

  3. Android实现Layout缩放动画

    最近看到Any.do的缩放效果很酷,看到一篇讲Layout缩放动画实现的文章,记录一下: http://edison-cool911.iteye.com/blog/704812

  4. 动画--问题追踪:ImageView执行缩放动画ScaleAnimation之后,图像显示不全的问题。

    http://www.bkjia.com/Androidjc/929473.html: 问题追踪:ImageView执行缩放动画ScaleAnimation之后,图像显示不全的问题., 问题:我有一个 ...

  5. iOS开发笔记10:圆点缩放动画、强制更新、远程推送加语音提醒及UIView截屏

    1.使用CAReplicatorLayer制作等待动画 CALayer+CABasicAnimation可以制作很多简单的动画效果,之前的博客中介绍的“两个动画”,一个是利用一张渐变色图片+CABas ...

  6. AndroidUI 视图动画-缩放动画效果 (ScaleAnimation)

    放动画效果,可以使用ScaleAnimation: <Button android:id="@+id/btnScale2" android:layout_width=&quo ...

  7. AndroidTv Home界面实现原理(二)——Leanback 库的主页卡位缩放动画源码解析

    先看个效果图: 上一篇中,我们留了问题,在 Tv Home 界面这种很常见聚焦卡位放大动画效果,我们这一篇就来看看 Leanback 库是怎么实现的. 如果要我们自己实现的话,思路应该不难,就是写个放 ...

  8. Android缩放动画

    Android缩放动画 核心方法 public void startAnimation(Animation animation) 执行动画,参数可以是各种动画的对象,Animation的多态,也可以是 ...

  9. UI设计篇·入门篇·简单动画的实现,透明动画/旋转动画/移动动画/缩放动画,混合动画效果的实现,为动画设置监听事件,自定义动画的方法

    基本的动画构成共有四种:透明动画/旋转动画/移动动画/缩放动画. 配置动画的方式有两种,一种是直接使用代码来配置动画效果,另一种是使用xml文档配置动画效果 相比而言,用xml文档写出来的动画效果,写 ...

随机推荐

  1. abtest分流随机链接方法(javascript)

    ¶¹¸¯¸ÉËêµÄ·¨¹úµçÊÓ¸²¸Ç --> 代码如下 <!DOCTYPE HTML> <html> <head> <script type=& ...

  2. Web Api之Cors跨域以及其他跨域方式(三)

    我们知道ajax不能跨域访问,但是有时我们确实需要跨域访问获取数据,所以JSONP就此诞生了,其本质使用的是Script标签,除JSONP以外还有另外实现跨域方式 一.手动实现JSONP跨域 1.首先 ...

  3. 开始Hibernate介绍

    1.介绍 一个框架 一个Java领域内的持久化框架 一个ORM框架 2.持久化 和数据库相关的各种操作 保存 更新 删除 查询 加载:根据特定的OID,把一个对象从数据库加载到你内存中. OID:为了 ...

  4. 005 爬虫(requests与beautifulSoup库的使用)

    一:知识点 1.安装requests库 2.Brautiful soup 可以提供一些简单的,python式的函数来处理导航,搜索,修改分析树等功能. 她是一个工具箱,通过解析文档为用户提供需要抓去的 ...

  5. Yii2之控制台命令篇(console)

    控制台命令 Yii 中有一个拥有丰富功能的控制台,它们主要用于创建网站后台处理的任务.在项目根目录下执行相关操作,有意思的事,可以通过 yii 自带的功能,列出当前已有的命令. 1.查看当前项目控制台 ...

  6. CentOS源码安装搭建LNMP全过程(包括nginx,mysql,php,svn)

    服务器环境为:CentOS6.5 64位 目标:搭建LNMP(Linux + Nginx + MySQL + PHP +SVN),其中svn是用来代替ftp,方便开发中调试同步代码 相关目录:所有软件 ...

  7. thinkphp数据查询方法总结select ,find,getField,query

    thinkphp已经封装好了常用的查询方法,且都比较实用,对于不常用的查询框架也保留了原始查询方法query. 1 2 $Model = new Model() // 实例化一个model对象 没有对 ...

  8. 1032 Sharing (25)(25 point(s))

    problem To store English words, one method is to use linked lists and store a word letter by letter. ...

  9. Codeforces.809E.Surprise me!(莫比乌斯反演 虚树)

    题目链接 \(Description\) 给定一棵树,求\[\frac{1}{n(n-1)/2}\times\sum_{i\in[1,n],j\in[1,n],i\neq j}\varphi(a_i\ ...

  10. vijos p1881 线段树

    题意:点我 我就想问,现在换代码风格还来得及吗? 2015-05-19:线段树进一步加强,看来不用换风格了 维护左右节点左右端颜色和长度即可 #include<cstdio> #inclu ...