滑动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. 编写dimgr脚本学到的知识及技巧

    编写dimgr是为了管理手机上的镜像,在此总结下过程中学到的知识及技巧(不讨论具体用法). 参数处理 以往处理脚本参数直接用循环加判断语句,若是脚本只有简单参数,这无疑是简便可行的方法.但当需要处理复 ...

  2. Oracle 12c Lnux 启动脚本

    #!/bin/bash # #oracle: Start/Stop Oracle Database 11g R2/12c # # chkconfig: # description: The Oracl ...

  3. Java 和 JSP 实现网站访问量统计 (刷新过滤)

    java 和 JSP 实现的统计网站访问量,不需要数据库,将数据存储在 指定位置的 txt 文件中,代码块分为两部分 首先, java 部分: import java.io.File; import ...

  4. mvc 提交Html内容的处理

    默认   方法1 [ValidateInput(false)] 这个方法会完全开放,对于有些字段允许,有些字段不允许的情况,是不会检测的   方法2 [AllowHtml] 此方法只有再使用Defau ...

  5. 【转】手机web前端调试页面的几种方式

    前言 PC端web页面调试比较容易,这里主要说几种移动端调试的方法,从简单到复杂.从模拟调试到远程调试,大概分为几部分: 1.Chrome DevTools(谷歌浏览器)的模拟手机调试 2.weinr ...

  6. Java并发常见问题

    ConcurrentHashMap源码分析,参考:http://blog.csdn.net/do_smile/article/details/46911727 HashMap源码分析,参考:http: ...

  7. Java Swing实战(五)表格组件JTable(1)

    dbPanel面板的配置告一段落. 接下来配置taskPanel 面板. /** * @author: lishuai * @date: 2018/11/26 13:51 */ public clas ...

  8. golang使用graphviz

    graphviz的介绍请参考: http://www.cnblogs.com/ghj1976/p/4539788.html  安装 graphviz 需要在 http://www.graphviz.o ...

  9. hdu 2612

    Find a way Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  10. 给model模型传数组参数

    $res = $this->Company->companyDischarge($this->user_id,array(0=>'c.limit_sum>0',1=> ...