滑动cell的时候执行动画效果

效果图:

源码:

//
// ViewController.m
// AniTab
//
// Created by XianMingYou on 15/2/26.
// Copyright (c) 2015年 XianMingYou. All rights reserved.
// #import "ViewController.h"
#import "ShowCell.h" @interface ViewController ()<UITableViewDataSource, UITableViewDelegate> @property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataSource; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; // 初始化数据源
self.dataSource = [NSMutableArray new];
for (int i = ; i < ; i++) {
[self.dataSource addObject:[NSString stringWithFormat:@"%02d YouXianMing", i]];
} // 初始化tableView
self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds
style:UITableViewStylePlain];
[self.view addSubview:self.tableView];
self.tableView.delegate = self;
self.tableView.dataSource = self;
[self.tableView registerClass:[ShowCell class]
forCellReuseIdentifier:@"ShowCell"];
} #pragma mark - tableView代理
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.dataSource.count;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
ShowCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ShowCell"];
[cell accessData:self.dataSource[indexPath.row]]; return cell;
} #pragma mark cell显示的时候
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
ShowCell *showCell = (ShowCell *)cell;
[showCell show];
} #pragma mark cell消失的时候
- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath {
ShowCell *showCell = (ShowCell *)cell;
[showCell hide];
} #pragma mark cell高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return ;
} @end

cell源码:

//
// ShowCell.h
// AniTab
//
// Created by XianMingYou on 15/2/26.
// Copyright (c) 2015年 XianMingYou. All rights reserved.
// #import <UIKit/UIKit.h> @interface ShowCell : UITableViewCell /**
* 动画显示
*/
- (void)show; /**
* 动画隐藏
*/
- (void)hide; /**
* 处理数据
*
* @param data 数据源
*/
- (void)accessData:(id)data; @end
//
// ShowCell.m
// AniTab
//
// Created by XianMingYou on 15/2/26.
// Copyright (c) 2015年 XianMingYou. All rights reserved.
// #import "ShowCell.h" @interface ShowCellStoreValue : NSObject
@property (nonatomic) CGRect startRect;
@property (nonatomic) CGRect endRect;
@end
@implementation ShowCellStoreValue
@end @interface ShowCell () @property (nonatomic, strong) UILabel *label;
@property (nonatomic, strong) ShowCellStoreValue *storeValue; @end @implementation ShowCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.label = [[UILabel alloc] initWithFrame:CGRectMake(, , , )];
self.label.font = [UIFont italicSystemFontOfSize:.f];
[self addSubview:self.label]; self.storeValue = [ShowCellStoreValue new];
self.storeValue.startRect = self.label.frame;
self.storeValue.endRect = CGRectMake(, + , , );
} return self;
} - (void)accessData:(id)data {
NSString *str = data;
if ([str isKindOfClass:[NSString class]]) {
self.label.text = str;
}
} /**
* 动画显示
*/
- (void)show {
[UIView animateWithDuration:.f animations:^{
self.label.frame = self.storeValue.endRect;
}];
} - (void)hide {
[self.label.layer removeAllAnimations];
self.label.frame = self.storeValue.startRect;
} @end

原理:

滑动cell的时候执行动画效果的更多相关文章

  1. 点击单个cell高度变化的动画效果

    点击单个cell高度变化的动画效果 效果 说明 1. 点击单个cell的时候,其展开与缩放动画实现起来是很麻烦的,做过相关需求的朋友一定知道其中的坑 2. 本例子只是提供了一个解决方案,为了简化操作, ...

  2. 随着ScrollView的滑动,渐渐的执行动画View

    今天是实现了一个小功能的东西.看看效果图: 实现方式: 1.自定义ScrollView   复写onScrollChange方法,来计算滑动的位置. 2.自定义接口,通过接口来在ScrollView中 ...

  3. swift中实现cell中局部播放的动画效果

    在cell中 // 播放器动画效果 private var replicatorLayer:ReplicatorLayer = { let layer = ReplicatorLayer.init(f ...

  4. 114自定义UITableViewCell(扩展知识:为UITableViewCell添加动画效果)

    关键操作: 效果如下: ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UITableViewCo ...

  5. CSS3 动画效果带来的bug

    css3 动画效果比如transition:all 2s linear;这种用来计算及时的物体坐标的话会带来一定的问题 比如把一个DIV从A点移动到B点.JS为DIV.style.left=B; 但是 ...

  6. 【转】Android 实现蘑菇街购物车动画效果

    原文出处:http://blog.csdn.net/wangjinyu501/article/details/38400479 1.思路   目前想到两种方式实现这种效果,一是使用Tween动画,直截 ...

  7. 对于 NSLayoutConstraint 不执行动画的处理:

    在开发中  我们有时候需要改变某个空间的约束条件 也就是更改NSLayoutConstraint的值  (比如说我想在键盘顶部增加一个工具栏 让工具栏随着键盘的位置变化而变化  有一个动画效果)但是发 ...

  8. jquery动画效果中,避免持续反应用户的连续点击

    一.某些动画效果中,避免持续连续反应用户的连续点击(这标题真不好描述) 意思就是指用户点击速度很快,完成一次效果的时间不能很快结束的话,就会出现用户不点击了,效果还在持续.看下面例子就明白了,手风琴效 ...

  9. CSS自学笔记(14):CSS3动画效果

    在CSS3中也新增了一些能够对元素创建动画处理的属性.通过这些新增的属性,我们可以实现元素从一种样式变换成另一种样式时为元素添加动态效果,我们就可以取代网页中的动态图片.flash动画和JavaScr ...

随机推荐

  1. 安装scrapy报错 error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools

    报错内容:Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools" ...

  2. Go 压测

    1. 单测 + 压测 压测 go test -bench=. -benchmem 单元测试 go test -v . 2. pprof + 火焰图(查看cpu占用,内存占用) 嵌入代码 import ...

  3. for循环的3个参数

    1.最常用的方法是用来遍历集合 /** **第一个参数:表示循环的初始值,或初始条件,这里是i=0; **第二个参数:是循环的条件,这里是当i小于list的长度时; **第三个参数:每次循环要改变的操 ...

  4. springMVC实现json

    很多时候前端都需要调用后台服务实现交互功能,常见的数据交换格式多是JSON或XML,这里主要讲解Spring MVC为前端提供JSON格式的数据并实现与前台交互. 一.概要 JSON(JavaScri ...

  5. ES6 笔记(二)- 总结

        在最近进行的项目中,已经全面使用到ES6,这里对ES6进行整理总结.用得比较多的是带*的内容,这些语法.新增类型.模块调用等从代码量上.可读性上.操作上给项目带来了不少便利.   1.语法 1 ...

  6. Qt Model View 框架

    Model-View及Qt实现 Model-View-Controller架构最早出现在SmallTalk语言中,至今出现了很多变体. Model是负责维护数据(如管理数据库),View负责显示与用户 ...

  7. IE浏览器版本的判断

    var userAgent = navigator.userAgent; //取得浏览器的userAgent字符串 && userAgent.indexOf(; //判断是否IE< ...

  8. CSS3完善和模式

    CSS3改善了传统盒模型架构,增强盒子构成要素的功能,扩展了盒模型显示的方式,具体描述如下 改善构造:除了传统的内容区域,边框区,补白区和边界区外,为盒子新增了轮廓区. 增强功能:内容增强CSS自动添 ...

  9. ASP.NET Url 重写

    protected void Application_BeginRequest(object sender, EventArgs e) { string url = Request.AppRelati ...

  10. Zookeeper学习文章目录1

    目录:参考文章如下 1.ZooKeeper学习第一期---Zookeeper简单介绍 2. ZooKeeper学习第二期--ZooKeeper安装配置 3. ZooKeeper学习第三期---Zook ...