//
// 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添加动效的更多相关文章

  1. 前端必须收藏的CSS3动效库!!!

    现在的网站和App的设计中越来越重视用户体验,而优秀的动效则能使你的应用更具交互性,从而吸引更多用户的使用. 如果你对CSS3中定义动效还不熟练,或希望采用更加简单直接的方式在你的应用中引入动效的话, ...

  2. 【总结】前端必须收藏的CSS3动效库!!!

    现在的网站和App的设计中越来越重视用户体验,而优秀的动效则能使你的应用更具交互性,从而吸引更多用户的使用. 如果你对CSS3中定义动效还不熟练,或希望采用更加简单直接的方式在你的应用中引入动效的话, ...

  3. 实现一个带有动效的 React 弹窗组件

    我们在写一些 UI 组件时,若不考虑动效,就很容易实现,主要就是有无的切换(类似于 Vue 中的 v-if 属性)或者可见性的切换(类似于 Vue 中的 v-show 属性). 1. 没有动效的弹窗 ...

  4. iOS collectionView添加类似tableView的tableHeaderView

    我们都知道UITableview有一个tableHeaderFooterView,这样我们在布局页面的时候,如果顶部有轮播图,可以直接把轮播图设置为tableView的HeaderFooterView ...

  5. tableview折叠动效

    缘起于看见书旗小说的列表有点击折叠的动效,觉得十分炫酷.想了三分钟,不知道怎么写.晚上百度了下,知道了大致流程,于是自己实现了下,发现不少坑,于是写下这篇博文 实现原理: 1 tableview ce ...

  6. iOS开发Facebook POP动效库使用教程

    如果说Origami这款动效原型工具是Facebook Paper的幕后功臣,那么POP便是Origami的地基.感谢Facebook开源了POP动效库,让人人都能制作出华丽的动效.我们只需5步,便能 ...

  7. 用AE如何制作如下三个loading动效,

    在本期象牙绘UED团队分享当中,我们将详细演示用AE如何制作如下三个loading动效, 其中涉及到AE表达式的应用.值曲线调整.速度曲线编辑等知识. 对于初学者来说可能信息量略大,希望通过是视频教程 ...

  8. 动效解析工厂:Mask 动画

    转载自:http://www.cocoachina.com/ios/20160214/15250.html 前言:很多动效都是多种动画的组合,有时候你可能只是需要其中某个动画,但面对庞杂的代码库或是教 ...

  9. iOS开发之 Lottie -- 炫酷的动效

    动效在软件开发中非常常见,炫酷的动画能提升应用的B格,然而由设计师的设计转化成程序猿GG的代码是个非常"痛苦"的过程.对于复杂动画,可能要花费很多时间去研究和实现.Lottie 的 ...

随机推荐

  1. javascript记忆

    Math.round()和ToFixed() Math.round(1.6)=2 Math.round(-1.4)=-1 var k = 1.74.toFixed(1), m = 1.75.toFix ...

  2. UDF、UDAF、UDTF函数编写

    一.UDF函数编写 1.步骤 1.继承UDF类 2.重写evalute方法 .继承GenericUDF .实现initialize.evaluate.getDisplayString方法 2.案例 实 ...

  3. Number String(DP)

    题目: 题意: 给你一个字符串s,s[i] = 'D'表示排列中a[i] > a[i+1],s[i] = 'I'表示排列中a[i] < a[i+1]. 比如排列 {3, 1, 2, 7, ...

  4. 转 国内的go get问题的解决

    转 国内的go get问题的解决     go get golang.org/x 包失败解决方法 由于各种问题,国内使用 go get 安装 golang 官方包可能会失败,如我自己在安装 colli ...

  5. CSRF自动化检测

    CSRF自动化检测: 这里主要是对POST型form表单的检测 1. 根据URL获取form表单组成的数组 2. 遍历表单数组,对比不设置cookie与设置了cookie两种情况下的表单是否还存在,如 ...

  6. ubuntu安装虚拟环境

    首先 sudo pip install virtualenv sudo pip install virtualenvwrapper 然后进行配置 sudo gedit /.bashrc export ...

  7. C#如何Json转字符串;字符串转Json;Newtonsoft.Json(Json.Net)

    Newtonsoft.Json,一款.NET中开源的Json序列化和反序列化类库(下载地址http://json.codeplex.com/). 下面是Json序列化和反序列化的简单封装: /// & ...

  8. C# 委托简单例子

    public delegate double Delegate_Prod(int a,int b); class Class1 { static double fn_Prodvalues(int va ...

  9. [蓝点ZigBee] Zstack 之点亮LED灯 ZigBee/CC2530 视频资料

    LED点灯实验,主要是依据Zstack 现有程序修改LED相关驱动,适配到我们自己的开发板上,我们开发板共有4个LED灯,其中一个是电源指示灯,剩余3个都是GPIO控制的LED灯,有LED 灯连接方式 ...

  10. [P1879][USACO06NOV]玉米田Corn Fields (状态压缩)

    最近题目都有状态压缩,我是蒟蒻,并不会状态压缩 然后我决定学了! 然后发现我学不来. OI-WIKI上的界面给我推荐了这道题https://oi-wiki.org/dp/state/ 状态压缩入门题, ...