如何给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 的 ...
随机推荐
- hive有关函数
1.窗口函数2015年4月份购买过的顾客及总人数 select distinct name,count(1) over() as cnt from test_window_yfwhere substr ...
- 使用Nginx+uwsgi在亚马逊云服务器上部署python+django项目完整版(二)——部署配置及相关知识
---恢复内容开始--- 一.前提: 1.django项目文件已放置在云服务器上,配置好运行环境,可正常运行 2.云服务器可正常连接 二.相关知识 1.python manage.py runserv ...
- Git rebase命令实战
一.前言 一句话,git rebase 可以帮助项目中的提交历史干净整洁!!! 二.避免合并出现分叉现象 git merge操作 1.新建一个 develop 分支 2.在develop分支上新建 ...
- DevOps: CLM, RLM, RPM, RPD, BSA, BAA, BMA - WOW!
1. BMC Release Lifecycle Management (RLM) is our suite targeted at managing and automating applicati ...
- 将ant Design本地化,可通过link以及script直接引入html中使用
一直想着能本地化antd的,不用npm以及dva那么复杂的配置环境来开发,并且本地化以后对以后链接flask的模板渲染机制也能很好的结合.下面是具体的实现方法: 1.将react的相关链接引入: &l ...
- 大数据环境完全分布式搭建linux(centos)中安装zookeeper
切记 要关闭防火墙 chkconfig iptables off(关闭防火墙的命令) 1.解压安装包 tar -zxvf zookeeper-3.4.5.tar.gz 2.在conf文件夹下 修改 ...
- JS运算符问题
以下代码是否报错,如果不报错输出什么,为什么 var x = !!"Hello" + (!"world", !!"from here!!") ...
- Axis2部署后服务器端出现异常信息
客户端可以正常调用Web Service,但服务端控制台报出如下异常:2013-09-05 09:49:12,965:[http-8080-2] at org.apache.axis2.dataret ...
- Android的系统属性:build.propSystemProperties
获取build.prop的键值信息: String sn = SystemProperties.get(SN_INFO); 其中key值为: public static final String SN ...
- 【DWM1000】 非官方开源定位代码bitcraze
蓝点DWM1000 模块已经打样测试完毕,有兴趣的可以申请购买了,更多信息参见 蓝点论坛 正文: 最近关注DWM1000 定位,一方面在看DWM1000 官方提供的代码,也在四处网上找资料看资料. 其 ...