如何给TableView、CollectionView添加动效
//
// ViewController.m
// tableViewAnimation
//
// Created by 冯敏 on 2018/3/13.
// Copyright © 2018年 FengMin. All rights reserved.
// #import "ViewController.h" @interface ViewController () <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView * mainTableView;
@property (nonatomic, strong) NSArray * cells;
@end @implementation ViewController - (UITableView *)mainTableView {
if (!_mainTableView) {
_mainTableView = [[UITableView alloc] initWithFrame:self.view.bounds];
_mainTableView.delegate = self;
_mainTableView.dataSource = self;
}
return _mainTableView;
} - (void)viewDidLoad {
[super viewDidLoad];
self.cells = [NSArray array];
[self.view addSubview:self.mainTableView]; } //- (void)viewWillAppear:(BOOL)animated {
// [super viewWillAppear:animated];
// [self animationTable];
//} - (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self animationTable];
} #pragma mark - UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return ;
} - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 100.0f;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
cell.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.6];
cell.textLabel.text = [NSString stringWithFormat:@"%ld",(long)indexPath.row];
return cell;
} #pragma mark - UITableViewDelegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { } - (void)animationTable {
_cells = [_mainTableView.visibleCells copy];
[_mainTableView indexPathsForVisibleRows];
CGFloat tableHeight = _mainTableView.bounds.size.height; CGFloat duration = 0.1; for (UITableViewCell * cell in _cells) {
cell.transform = CGAffineTransformMakeTranslation(, tableHeight);
// [UIView animateWithDuration:3.0f animations:^{
// cell.transform = CGAffineTransformMakeTranslation(0, 0);
// }]; // cell.transform = CGAffineTransformMakeTranslation([UIScreen mainScreen].bounds.size.width, 0);
// [UIView animateWithDuration:duration delay:0 options:0 animations:^{
// cell.transform = CGAffineTransformIdentity;
// } completion:^(BOOL finished) {
//
// }];
duration += 0.1; [UIView animateWithDuration:3.0f delay:duration usingSpringWithDamping:0.8 initialSpringVelocity: options:nil animations:^{
cell.transform = CGAffineTransformMakeTranslation(, );
} completion:^(BOOL finished) { }];
} } - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
} - (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
// [UIView beginAnimations:nil context:nil];
// [UIView setAnimationDuration:0.2];
// cell.transform = CGAffineTransformMakeScale(0.9, 0.9);
// [UIView commitAnimations]; [UIView animateWithDuration:1.0f animations:^{
cell.transform = CGAffineTransformMakeScale(1.2, 1.2);
}];
} - (void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.2];
cell.transform = CGAffineTransformMakeScale(1.0, 1.0);
[UIView commitAnimations];
} //ios(8.0)
- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewRowAction * action = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
// [self.titleArr removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade]; }]; return @[action];
} //ios(11.0) 头部 左侧按钮自定义、右侧按钮自定义、自定义图片、背景颜色,通过 UIContextualAction 来设置
- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView leadingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath {
UIContextualAction * deleteRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"delete" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
// [self.titleArr removeObjectAtIndex:indexPath.row];
completionHandler (YES);
}];
deleteRowAction.image = [UIImage imageNamed:@"icon_del"];
deleteRowAction.backgroundColor = [UIColor blueColor]; UISwipeActionsConfiguration * config = [UISwipeActionsConfiguration configurationWithActions:@[deleteRowAction]];
return config;
} // 尾部
- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath {
UIContextualAction * deleteRowAction = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive title:@"delete" handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) {
// [self.titleArr removeObjectAtIndex:indexPath.row];
completionHandler (YES);
}];
deleteRowAction.image = [UIImage imageNamed:@"icon_del"];
deleteRowAction.backgroundColor = [UIColor blueColor]; UISwipeActionsConfiguration * config = [UISwipeActionsConfiguration configurationWithActions:@[deleteRowAction]];
return config;
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
如何给TableView、CollectionView添加动效的更多相关文章
- 前端必须收藏的CSS3动效库!!!
现在的网站和App的设计中越来越重视用户体验,而优秀的动效则能使你的应用更具交互性,从而吸引更多用户的使用. 如果你对CSS3中定义动效还不熟练,或希望采用更加简单直接的方式在你的应用中引入动效的话, ...
- 【总结】前端必须收藏的CSS3动效库!!!
现在的网站和App的设计中越来越重视用户体验,而优秀的动效则能使你的应用更具交互性,从而吸引更多用户的使用. 如果你对CSS3中定义动效还不熟练,或希望采用更加简单直接的方式在你的应用中引入动效的话, ...
- 实现一个带有动效的 React 弹窗组件
我们在写一些 UI 组件时,若不考虑动效,就很容易实现,主要就是有无的切换(类似于 Vue 中的 v-if 属性)或者可见性的切换(类似于 Vue 中的 v-show 属性). 1. 没有动效的弹窗 ...
- iOS collectionView添加类似tableView的tableHeaderView
我们都知道UITableview有一个tableHeaderFooterView,这样我们在布局页面的时候,如果顶部有轮播图,可以直接把轮播图设置为tableView的HeaderFooterView ...
- tableview折叠动效
缘起于看见书旗小说的列表有点击折叠的动效,觉得十分炫酷.想了三分钟,不知道怎么写.晚上百度了下,知道了大致流程,于是自己实现了下,发现不少坑,于是写下这篇博文 实现原理: 1 tableview ce ...
- iOS开发Facebook POP动效库使用教程
如果说Origami这款动效原型工具是Facebook Paper的幕后功臣,那么POP便是Origami的地基.感谢Facebook开源了POP动效库,让人人都能制作出华丽的动效.我们只需5步,便能 ...
- 用AE如何制作如下三个loading动效,
在本期象牙绘UED团队分享当中,我们将详细演示用AE如何制作如下三个loading动效, 其中涉及到AE表达式的应用.值曲线调整.速度曲线编辑等知识. 对于初学者来说可能信息量略大,希望通过是视频教程 ...
- 动效解析工厂:Mask 动画
转载自:http://www.cocoachina.com/ios/20160214/15250.html 前言:很多动效都是多种动画的组合,有时候你可能只是需要其中某个动画,但面对庞杂的代码库或是教 ...
- iOS开发之 Lottie -- 炫酷的动效
动效在软件开发中非常常见,炫酷的动画能提升应用的B格,然而由设计师的设计转化成程序猿GG的代码是个非常"痛苦"的过程.对于复杂动画,可能要花费很多时间去研究和实现.Lottie 的 ...
随机推荐
- JavaEE 之 Spring(三)
1.Spring Web MVC a.定义:是一种基于Java的实现了Web MVC设计模式的请求驱动类型的轻量级Web框架,即使用了MVC架构模式的思想,将web层进行职责解耦,基于请求驱动指的就是 ...
- Web Component
前言 Web Component不是新东西,几年前的技术,但是受限于浏览器兼容性,一直没有大规模应用在项目里,直到现在(2018年年末),除IE仍不支持之外,其它主流浏览器都支持Web Compone ...
- Github入门操作实录
到目前为止,我已经工作快5年了,这5年最大的感受就是,框架什么的并不难,只要知道api,就能用起来,一开始会遇到一点问题,但是天下的框架都大同小异,无非是jar包,配置文件,模板代码,jar包可以使用 ...
- [Python] Marshmallow QuickStart
常用小操作索引 指定fields必须:fields.String(required=True) 部分loading: 不load name:result = UserSchema.load({'ema ...
- BZOJ.1109.[POI2007]堆积木Klo(DP LIS)
BZOJ 二维\(DP\)显然.尝试换成一维,令\(f[i]\)表示,强制把\(i\)放到\(a_i\)位置去,现在能匹配的最多数目. 那么\(f[i]=\max\{f[j]\}+1\),其中\(j& ...
- Java经典面试题(一)
1.在 Java 中类的定义在 Java 中,类是用于创建对象和定义数据类型的模板. 它充当面向 Java 语言的系统的构建块.2.静态加载和动态加载有什么区别?静态类加载涉及使用新关键字来创建对象和 ...
- docker 导出导入镜像
1.docker export jenkins > my_jenkins.tar 导出镜像到本地 cat my_jenkins | docker import my_jenkens:0.0. ...
- SSH密钥登录让Linux VPS/服务器更安全
查看 /var/log 登录日志文件,突然发现服务器被人扫描端口在进行暴力攻击 平常登录服务器,都是使用用户密码登录,看来这样的做法并不安全,不得不关闭密码登录了. 总结了一个putty使用密钥自动登 ...
- python系统编程(九)
同步的概念 1. 多线程开发可能遇到的问题 假设两个线程t1和t2都要对num=0进行增1运算,t1和t2都各对num修改10次,num的最终的结果应该为20. 但是由于是多线程访问,有可能出现下面情 ...
- pytorch写一个LeNet网络
我们先介绍下pytorch中的cnn网络 学过深度卷积网络的应该都非常熟悉这张demo图(LeNet): 先不管怎么训练,我们必须先构建出一个CNN网络,很快我们写了一段关于这个LeNet的代码,并进 ...