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文档写出来的动画效果,写 ...
随机推荐
- oracle centos 静默安装
http://blog.csdn.net/tongzidane/article/details/43852705 静默安装Oracle 11G过程中提示:Exception in thread &qu ...
- 【LOJ】#2290. 「THUWC 2017」随机二分图
题解 看了一眼觉得是求出图对图统计完美匹配的个数(可能之前做过这样模拟题弃疗了,一直心怀恐惧... 然后说是统计一下每种匹配出现的概率,也就是,当前左边点匹配状态为S,右边点匹配状态为T,每种匹配出现 ...
- USACO 6.5 Closed Fences
Closed Fences A closed fence in the plane is a set of non-crossing, connected line segments with N c ...
- CROC 2016 - Elimination Round (Rated Unofficial Edition) F - Cowslip Collections 数论 + 容斥
F - Cowslip Collections http://codeforces.com/blog/entry/43868 这个题解讲的很好... #include<bits/stdc++.h ...
- QT STUDY
- C++ 基础 杂类
1.set: 基本上跟map是相同(只有一个键),set是key-value 放在一起,map 是分开的,既然都加key ,所以set<> 的内容不可能有重复的情况出现 example: ...
- Kubernetes(k8s)集群部署(k8s企业级Docker容器集群管理)系列之集群部署环境规划(一)
0.前言 整体架构目录:ASP.NET Core分布式项目实战-目录 k8s架构目录:Kubernetes(k8s)集群部署(k8s企业级Docker容器集群管理)系列目录 一.环境规划 软件 版本 ...
- 使用DNSPod域名解析
1 在GoDaddy域名注册商 注册域名 https://sg.godaddy.com/zh/ 2 登陆DNSPod https://www.dnspod.cn 3 选择域名解析 添加域名 4 添加记 ...
- QT学习笔记4:QT中GraphicsView编程
一.QGraphicsScene 1.QGraphicsScene QGraphicsScene继承自QObject,是一个管理图元的容器,与QGraphicsView合用可以在2D屏幕上显示如线.三 ...
- 【构造】Codeforces Round #480 (Div. 2) B. Marlin
题意:给你一个4*n的网格,保证n为奇数,让你在其中放k个障碍物,不能放在边界的格子上,使得从左上角走到右下角的最短路的方案数,恰好等于从左下角走到右上角的最短路的方案数. k为偶数时,以纵向为对称轴 ...