滑动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 = 0; i < 40; i++) {[self.dataSource addObject:[NSString stringWithFormat:@"%02d YouXianMing", i]];}// 初始化tableViewself.tableView = [[UITableView alloc] initWithFrame:self.view.boundsstyle: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 100; }@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(10, 30, 300, 50)];self.label.font = [UIFont italicSystemFontOfSize:30.f];[self addSubview:self.label];self.storeValue = [ShowCellStoreValue new];self.storeValue.startRect = self.label.frame;self.storeValue.endRect = CGRectMake(10, 30 + 20, 300, 50);}return self; }- (void)accessData:(id)data {NSString *str = data;if ([str isKindOfClass:[NSString class]]) {self.label.text = str;} }/*** 动画显示*/ - (void)show {[UIView animateWithDuration:1.f animations:^{self.label.frame = self.storeValue.endRect;}]; }- (void)hide {[self.label.layer removeAllAnimations];self.label.frame = self.storeValue.startRect; }@end
原理:
转载于:https://www.cnblogs.com/YouXianMing/p/4300506.html
滑动cell的时候执行动画效果相关推荐
- html5 鼠标滑动页面动画效果,鼠标滑动到当前页面触发动画效果
近年来,关于鼠标滑动到当前页面从而触发动画效果十分的火热,今天我们就来学习下这一效果. 一.首先,我们先来了解一下这一效果实现的原理 1.一个网页离不开基本的布局,所以首先就是要先用html将所需要的 ...
- 22.调用delay()方法延时执行动画效果
delay()方法的功能是设置一个延时值来推迟动画效果的执行,它的调用格式为: $(selector).delay(duration) 其中参数duration为延时值,它的单位是毫秒,当超过延时值时 ...
- 轮播图动画滑动动画效果
轮播图的实现原理并不难,但是步骤有些繁琐.最近练习了一个轮播图,大部分是跟着网上的教程写的,然后自己做了一点兼容ie8的修改,加了点击切换图片的特效和手机端的滑动特效,让这个轮播图可以在响应式的网站中 ...
- 点击cell动态修改高度动画
点击cell动态修改高度动画 效果 源码 https://github.com/YouXianMing/Animations // // TapCellAnimationController.m // ...
- Android动画效果-更新中
概述 Android系统提供了三种实现动画的方式,一种是补间动画(Tween Animation 在SDK中成为View Animation),另一种是帧动画(Frame Animation 在SDK ...
- android炫酷的动画效果
这段时间看到一些比较好看的android动画效果,下面我就给大家一些我比较喜欢的动画效果,并附上源码希望对你们有用处. 1.很简单却很酷的粒子破碎效果 介绍: 实现思路 1.新建一个 Bean Pa ...
- Android实用技巧.动画效果(二)
LayoutAnimationController实现子布局进入动画效果 以listView为例设置item进入动画: 首先设置list界面 <?xml version="1.0&qu ...
- android实现购物车效果,Android 实现蘑菇街购物车动画效果
使用过蘑菇街的用户基本上都知道有一个加入购物车的动画效果,此处不具体描述想知道的可以去下载体验一下. 1.思路 目前想到两种方式实现这种效果,一是使用Tween动画,直截了当的进行一个移动,蘑菇街就是 ...
- 多个图标的动画效果(动画的衔接)
前面是一个图标的动画,这篇试一试多个图标的动画: 先创建四个图标, <span class="home icon">Home</span> <span ...
最新文章
- sysdba,sysoper,normal 以及sys,sysdba,dba概念区别
- Springboot项目中的favicon
- 29、C++ Primer 4th 笔记,异常处理
- 自定义view-波纹扩散(圆扩散)
- STM32 进阶教程 8 - 位带操作
- 【图像分类】分类专栏正式上线啦!初入CV、AI你需要一份指南针!
- 看看比尔·盖茨在关注什么
- Dom4j操作XML
- eventbus多个订阅_番石榴的EventBus –简单的发布者/订阅者
- 递归函数基例和链条_链条和叉子
- c++折线平移算法_RSA笔记-蒙哥马利算法(1)
- c语言闰年的判断条件DS1302,DS1302驱动程序(平年和闰年天数自动调整)
- Valak 6个月上演“变身戏法”,紧盯 Exchange 服务器窃取企业数据
- 【python】多进程小结
- 【计算机组成原理】重点总结(详版)
- python-2.找出数组中重复的数字
- js返回浏览器的顶部
- 读高明之《帛書老子校注》
- 系统安全及应用实验案例
- 点击按钮点击复制功能
热门文章
- Qt文档阅读笔记-QSslSocket中与错误相关的信号
- HTTP之Redirect和Location头使用(C++ Qt框架实现)
- Spring Boot中登录错误消息的显示
- 实现电子词典_它是一部电子词典,一部翻译机,一部口语机还是一部出游的随身WiFi...
- php三级实例,三级联动实例
- chart.js x轴显示不全_机床大讲堂第67讲——基于FANUC系统的数控铣床增加第四轴的方法...
- php网站不能访问,php怎么不登录不能访问
- 2018年工业机器人销量排位_2020年工业机器人统计数据新鲜出炉
- mysql触发器调用存储过程出错_mysql 触发器中调用存储过程
- abstract类中不可以有private的成员_C++ 类:声明成员函数与实现