滑动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 ...
随机推荐
- Oracle 12c Lnux 启动脚本
#!/bin/bash # #oracle: Start/Stop Oracle Database 11g R2/12c # # chkconfig: # description: The Oracl ...
- Tomcat 配置上传文件到项目外的路径
使用 Tomcat 作为服务器的时候,将上传文件保存在项目路径下,每次重启服务或者打成 war 包的时候很容易丢失上传的文件,于是我们配置 Tomcat 把文件保存到项目外的其他磁盘路径: 1. 打开 ...
- 虚拟机安装Linux中常见异常及解决办法
如果接着下去的提示按Test 的话 会出现Unable to read the disc checksum from the primary volume descriptor. This proba ...
- java linux ssh jar
Ganymed SSH-2 for Java http://www.ganymed.ethz.ch/ssh2/ Ganymed SSH-2 for Java is a library which im ...
- [转]Sql Server Report Service 的部署问题
本文转自:https://www.cnblogs.com/syfblog/p/4651621.html 近期在研究SSRS部署问题,因为以前也用到过SSRS报表,但当时开发的报表是有专门的集成系统的, ...
- IDEA 2019注册码
N757JE0KCT-eyJsaWNlbnNlSWQiOiJONzU3SkUwS0NUIiwibGljZW5zZWVOYW1lIjoid3UgYW5qdW4iLCJhc3NpZ25lZU5hbWUiO ...
- ef和mysql使用(二)--让mysql支持EntityFramework.Extended实现批量更新和删除
我们都知道Entity Framework 中不能同时更新多条记录,但是一个老外写的扩展库可以实现此功能EntityFramework.Extended,但是如何是mysql数据库要怎么实现呢 首先实 ...
- js静态数据分页展示
拿vue做示例 首先定义data data() { return { tableData: [], // 当前页的数据,用于给表格展示用的 tableDataAll: [], // 需要拿来分页的总数 ...
- php判断是否isPhone、is_weixin
protected function isPhone(){ $agent = strtolower($_SERVER['HTTP_USER_AGENT']); //pc请求头信息数组 $pc_arr= ...
- bootstrap学习笔记(表单)
1.基础表单 :对于基础表单,Bootstrap并未对其做太多的定制性效果设计,仅仅对表单内的fieldset.legend.label标签进行了定制. fieldset { min-width: 0 ...