滑动cell的时候执行动画效果
滑动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的时候执行动画效果的更多相关文章
- 点击单个cell高度变化的动画效果
点击单个cell高度变化的动画效果 效果 说明 1. 点击单个cell的时候,其展开与缩放动画实现起来是很麻烦的,做过相关需求的朋友一定知道其中的坑 2. 本例子只是提供了一个解决方案,为了简化操作, ...
- 随着ScrollView的滑动,渐渐的执行动画View
今天是实现了一个小功能的东西.看看效果图: 实现方式: 1.自定义ScrollView 复写onScrollChange方法,来计算滑动的位置. 2.自定义接口,通过接口来在ScrollView中 ...
- swift中实现cell中局部播放的动画效果
在cell中 // 播放器动画效果 private var replicatorLayer:ReplicatorLayer = { let layer = ReplicatorLayer.init(f ...
- 114自定义UITableViewCell(扩展知识:为UITableViewCell添加动画效果)
关键操作: 效果如下: ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UITableViewCo ...
- CSS3 动画效果带来的bug
css3 动画效果比如transition:all 2s linear;这种用来计算及时的物体坐标的话会带来一定的问题 比如把一个DIV从A点移动到B点.JS为DIV.style.left=B; 但是 ...
- 【转】Android 实现蘑菇街购物车动画效果
原文出处:http://blog.csdn.net/wangjinyu501/article/details/38400479 1.思路 目前想到两种方式实现这种效果,一是使用Tween动画,直截 ...
- 对于 NSLayoutConstraint 不执行动画的处理:
在开发中 我们有时候需要改变某个空间的约束条件 也就是更改NSLayoutConstraint的值 (比如说我想在键盘顶部增加一个工具栏 让工具栏随着键盘的位置变化而变化 有一个动画效果)但是发 ...
- jquery动画效果中,避免持续反应用户的连续点击
一.某些动画效果中,避免持续连续反应用户的连续点击(这标题真不好描述) 意思就是指用户点击速度很快,完成一次效果的时间不能很快结束的话,就会出现用户不点击了,效果还在持续.看下面例子就明白了,手风琴效 ...
- CSS自学笔记(14):CSS3动画效果
在CSS3中也新增了一些能够对元素创建动画处理的属性.通过这些新增的属性,我们可以实现元素从一种样式变换成另一种样式时为元素添加动态效果,我们就可以取代网页中的动态图片.flash动画和JavaScr ...
随机推荐
- Hive文件存储格式和hive数据压缩
一.存储格式行存储和列存储 二.Hive文件存储格式 三.创建语句和压缩 一.存储格式行存储和列存储 行存储可以理解为一条记录存储一行,通过条件能够查询一整行数据. 列存储,以字段聚集存储,可以理解为 ...
- 通过六个题目彻底掌握String笔试面试题
http://blog.csdn.net/chj97/article/details/6899598 1 public static void main(String[] args) { String ...
- SpringMVC form 表单提交报400错误
错误代码: HTTP Status 400 - type Status report message description The request sent by the client was sy ...
- PowerDesigner设置默认值名称规则
一.需求背景: 使用PowerDesigner创建表时,若设置某列默认值时,自动生成规则的默认值名称.比如说:DF_表名_列名 二.设置步骤: 1.选择Database—>Edit Curren ...
- 使用Python制作一个简单的刷博器
呵呵,不得不佩服Python的强大,寥寥几句代码就能做一个简单的刷博器. import webbrowser as web import time import os count=0 while co ...
- CSS3 @font-face实现颜色大小可控的三角效果——张鑫旭
一.我之前介绍过的三角实现效果回顾 这里所说的三角效果之等腰直角三角形效果(等边三角形有现成字符实现,没什么好说的:还有图片实现三角众人皆知,不予以说明): 1. 字符实现三角效果关于字符实现三角我早 ...
- .NET中的异步编程
开篇 异步编程是程序设计的重点也是难点,还记得在刚开始接触.net的时候,看的是一本c#的Winform实例教程,上面大部分都是教我们如何使用Winform的控件以及操作数据库的实例,那时候做的基本都 ...
- SQL SERVER DATETIME应用
),, , ),); ),, ),); ),, , ),); ),, ),); ),, , ),); ),, ),); How to get first and last day of previou ...
- BZOJ4144: [AMPPZ2014]Petrol(最短路 最小生成树)
题意 题目链接 Sol 做的时候忘记写题解了 可以参考这位大爷 #include<bits/stdc++.h> #define Pair pair<int, int> #def ...
- DNS必知必会
什么是DNS? DNS服务器(Domain Name Server,域名服务器)是进行域名和与之相对应的IP地址进行转换的服务器. 基本概念 DNS服务器中保存了一张域名和与之相对应的IP地址 的表, ...