UITableView的headerView展开缩放动画
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展开缩放动画的更多相关文章
- Swift - UITableView展开缩放动画
Swift - UITableView展开缩放动画 效果 源码 https://github.com/YouXianMing/Swift-Animations // // HeaderViewTapA ...
- 仿Inshot分享页图片圆形展开缩放动画
版权声明:本文为xing_star原创文章,转载请注明出处! 本文同步自http://javaexception.com/archives/221 圆形展开缩放动画 关键代码: final Anima ...
- Android实现Layout缩放动画
最近看到Any.do的缩放效果很酷,看到一篇讲Layout缩放动画实现的文章,记录一下: http://edison-cool911.iteye.com/blog/704812
- 动画--问题追踪:ImageView执行缩放动画ScaleAnimation之后,图像显示不全的问题。
http://www.bkjia.com/Androidjc/929473.html: 问题追踪:ImageView执行缩放动画ScaleAnimation之后,图像显示不全的问题., 问题:我有一个 ...
- iOS开发笔记10:圆点缩放动画、强制更新、远程推送加语音提醒及UIView截屏
1.使用CAReplicatorLayer制作等待动画 CALayer+CABasicAnimation可以制作很多简单的动画效果,之前的博客中介绍的“两个动画”,一个是利用一张渐变色图片+CABas ...
- AndroidUI 视图动画-缩放动画效果 (ScaleAnimation)
放动画效果,可以使用ScaleAnimation: <Button android:id="@+id/btnScale2" android:layout_width=&quo ...
- AndroidTv Home界面实现原理(二)——Leanback 库的主页卡位缩放动画源码解析
先看个效果图: 上一篇中,我们留了问题,在 Tv Home 界面这种很常见聚焦卡位放大动画效果,我们这一篇就来看看 Leanback 库是怎么实现的. 如果要我们自己实现的话,思路应该不难,就是写个放 ...
- Android缩放动画
Android缩放动画 核心方法 public void startAnimation(Animation animation) 执行动画,参数可以是各种动画的对象,Animation的多态,也可以是 ...
- UI设计篇·入门篇·简单动画的实现,透明动画/旋转动画/移动动画/缩放动画,混合动画效果的实现,为动画设置监听事件,自定义动画的方法
基本的动画构成共有四种:透明动画/旋转动画/移动动画/缩放动画. 配置动画的方式有两种,一种是直接使用代码来配置动画效果,另一种是使用xml文档配置动画效果 相比而言,用xml文档写出来的动画效果,写 ...
随机推荐
- ubuntu编译安装postgresql
闲着没事用源码编译安装了postgresql,遇到了不少故障,记录一下. 1:用./configure配置时发生错误.看信息说是缺少相关包.有什么readline,zlip等. 我配置的很简单,只是配 ...
- bzoj 1831
思路:随便猜一猜填的数字是不下降的,反证很好证明,然后就没了.. #include<bits/stdc++.h> #define LL long long #define fi first ...
- Ionic Js四:复选框
ionic 复选框(checkbox)与普通的 HTML 复选框没什么区别,以下实例演示了 ionic 复选框 ion-checkbox 的应用. <ion-checkbox ng-model= ...
- 有关FPGA
在FPGA发展历史上,前后共有过超过50家厂商,在国外目前剩下不到10家,除赛灵思和ALTERA两家持续不断地军备竞赛,其它的都有着各自固守的市场定位.即使是有新进入者,例如受英特尔新工艺支 ...
- Linux命令学习<不断更新>
没有系统的学习过Linux命令,遇到了就学习一下,慢慢积累. 1.echo 命令,学习网站『https://linux.cn/article-3948-1.html』. echo单词有回声.共鸣的意思 ...
- Spring之Spring环境搭建
Spring之Spring环境搭建 一.什么是Spring? Spring框架是由于软件开发的复杂性而创建的.Spring使用的是基本的JavaBean来完成以前只可能由EJB完成的事情.然而,Spr ...
- Tomcat CVE-2017-12615 远程上传漏洞复现
漏洞名称:CVE-2017-12615-远程代码执行漏洞 CVE-2017-12615:远程代码执行漏洞 当 Tomcat运行在Windows操作系统时,且启用了HTTP PUT请求方法(例如,将 r ...
- hdu 4417 区间内比h小的数 线段树
题意求区间内比h小的数的个数 将所有的询问离线读入之后,按H从小到大排序.然后对于所有的结点也按从小到大排序,然后根据查询的H,将比H小的点加入到线段树,然后就是一个区间和. 2015-07-27:专 ...
- the elements of computing systems 的读书笔记2
懒癌发作,本来计划是两到三天就一个unit的,没想到一直拖到今天才完成第二部分(6-8章). 第6章,介绍了hack汇编到二进制,也就是用翻译到01来表示.从课后习题来看,这一章目的就是设计一个程序( ...
- Git_忽略特殊文件
有些时候,你必须把某些文件放到Git工作目录中,但又不能提交它们,比如保存了数据库密码的配置文件啦,等等,每次git status都会显示“Untracked files ...”,有强迫症的童鞋心里 ...