UITableView中cell点击的绚丽动画效果

本人视频教程系类   iOS中CALayer的使用

效果图:

源码:

YouXianMingCell.h 与 YouXianMingCell.m

  1. //
  2. // YouXianMingCell.h
  3. // CellAnimation
  4. //
  5. // Created by YouXianMing on 14/12/27.
  6. // Copyright (c) 2014年 YouXianMing. All rights reserved.
  7. //
  8.  
  9. #import <UIKit/UIKit.h>
  10.  
  11. @interface YouXianMingCell : UITableViewCell
  12.  
  13. @property (nonatomic, strong) UILabel *name;
  14.  
  15. - (void)showIconAnimated:(BOOL)animated;
  16. - (void)hideIconAnimated:(BOOL)animated;
  17.  
  18. - (void)showSelectedAnimation;
  19.  
  20. @end
  1. //
  2. // YouXianMingCell.m
  3. // CellAnimation
  4. //
  5. // Created by YouXianMing on 14/12/27.
  6. // Copyright (c) 2014年 YouXianMing. All rights reserved.
  7. //
  8.  
  9. #import "YouXianMingCell.h"
  10.  
  11. @interface YouXianMingCell ()
  12.  
  13. @property (nonatomic, strong) UIImageView *iconView;
  14. @property (nonatomic, strong) UIView *lineView;
  15. @property (nonatomic, strong) UIView *rectView;
  16.  
  17. @end
  18.  
  19. @implementation YouXianMingCell
  20.  
  21. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  22. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  23. if (self) {
  24.  
  25. _rectView = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
  26. _rectView.layer.borderWidth = .f;
  27. _rectView.layer.borderColor = [UIColor grayColor].CGColor;
  28. [self addSubview:_rectView];
  29.  
  30. // 图标
  31. _iconView = [[UIImageView alloc] initWithFrame:CGRectMake(, , , )];
  32. _iconView.image = [UIImage imageNamed:@"icon"];
  33. _iconView.alpha = .f;
  34. [self addSubview:_iconView];
  35.  
  36. // 文字
  37. _name = [[UILabel alloc] initWithFrame:CGRectMake(, , , )];
  38. _name.font = [UIFont fontWithName:@"HelveticaNeue-Thin" size:];
  39. _name.textColor = [UIColor grayColor];
  40. [self addSubview:_name];
  41.  
  42. _lineView = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
  43. _lineView.alpha = .f;
  44. _lineView.backgroundColor = [UIColor redColor];
  45. [self addSubview:_lineView];
  46. }
  47.  
  48. return self;
  49. }
  50.  
  51. - (void)showIconAnimated:(BOOL)animated {
  52. if (animated) {
  53. _iconView.transform = CGAffineTransformMake(, , , , , );
  54.  
  55. [UIView animateWithDuration:0.5
  56. delay:
  57. usingSpringWithDamping:
  58. initialSpringVelocity:
  59. options:UIViewAnimationOptionCurveEaseInOut
  60. animations:^{
  61. _iconView.alpha = .f;
  62. _iconView.transform = CGAffineTransformMake(, , , , , );
  63.  
  64. _lineView.alpha = .f;
  65. _lineView.frame = CGRectMake(, , , );
  66.  
  67. _name.frame = CGRectMake( + , , , );
  68.  
  69. _rectView.layer.borderColor = [UIColor redColor].CGColor;
  70. _rectView.transform = CGAffineTransformMake(0.8, , , 0.8, , );
  71. _rectView.layer.cornerRadius = .f;
  72. }
  73. completion:^(BOOL finished) {
  74.  
  75. }];
  76. } else {
  77. _iconView.transform = CGAffineTransformMake(, , , , , );
  78. _iconView.alpha = .f;
  79.  
  80. _lineView.alpha = .f;
  81. _lineView.frame = CGRectMake(, , , );
  82.  
  83. _name.frame = CGRectMake( + , , , );
  84.  
  85. _rectView.layer.borderColor = [UIColor redColor].CGColor;
  86. _rectView.transform = CGAffineTransformMake(0.8, , , 0.8, , );
  87. _rectView.layer.cornerRadius = .f;
  88. }
  89. }
  90.  
  91. - (void)hideIconAnimated:(BOOL)animated {
  92. if (animated) {
  93. [UIView animateWithDuration:0.5
  94. delay:
  95. usingSpringWithDamping:
  96. initialSpringVelocity:
  97. options:UIViewAnimationOptionCurveEaseInOut
  98. animations:^{
  99. _iconView.alpha = .f;
  100. _iconView.transform = CGAffineTransformMake(0.5, , , 0.5, , );
  101.  
  102. _lineView.alpha = .f;
  103. _lineView.frame = CGRectMake(, , , );
  104.  
  105. _name.frame = CGRectMake(, , , );
  106.  
  107. _rectView.layer.borderColor = [UIColor grayColor].CGColor;
  108. _rectView.transform = CGAffineTransformMake(, , , , , );
  109. _rectView.layer.cornerRadius = ;
  110. }
  111. completion:^(BOOL finished) {
  112.  
  113. }];
  114. } else {
  115. _iconView.alpha = .f;
  116.  
  117. _lineView.alpha = .f;
  118. _lineView.frame = CGRectMake(, , , );
  119.  
  120. _name.frame = CGRectMake(, , , );
  121.  
  122. _rectView.layer.borderColor = [UIColor grayColor].CGColor;
  123. _rectView.transform = CGAffineTransformMake(, , , , , );
  124. _rectView.layer.cornerRadius = ;
  125. }
  126. }
  127.  
  128. - (void)showSelectedAnimation {
  129. UIView *tmpView = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
  130. tmpView.backgroundColor = [[UIColor yellowColor] colorWithAlphaComponent:0.30];
  131. tmpView.alpha = .f;
  132.  
  133. [self addSubview:tmpView];
  134.  
  135. [UIView animateWithDuration:0.20 delay: options:UIViewAnimationOptionCurveEaseIn animations:^{
  136. tmpView.alpha = 0.8f;
  137. } completion:^(BOOL finished) {
  138. [UIView animateWithDuration:0.20 delay:0.1 options:UIViewAnimationOptionCurveEaseOut animations:^{
  139. tmpView.alpha = .f;
  140. } completion:^(BOOL finished) {
  141. [tmpView removeFromSuperview];
  142. }];
  143. }];
  144. }
  145.  
  146. @end

控制器源码:

  1. //
  2. // ViewController.m
  3. // CellAnimation
  4. //
  5. // Created by YouXianMing on 14/12/27.
  6. // Copyright (c) 2014年 YouXianMing. All rights reserved.
  7. //
  8.  
  9. #import "ViewController.h"
  10. #import "YouXianMingCell.h"
  11.  
  12. static NSString *YouXianMingCellFlag = @"YouXianMingCell";
  13.  
  14. @interface ViewController ()<UITableViewDelegate, UITableViewDataSource>
  15.  
  16. @property (nonatomic, strong) UITableView *tableView;
  17.  
  18. @property (nonatomic, strong) NSMutableArray *dataArray;
  19. @property (nonatomic, strong) NSMutableArray *chooseArray;
  20.  
  21. @end
  22.  
  23. @implementation ViewController
  24.  
  25. - (void)viewDidLoad {
  26. [super viewDidLoad];
  27.  
  28. // 初始化数据源
  29. _dataArray = [NSMutableArray array];
  30. _chooseArray = [NSMutableArray array];
  31.  
  32. [_dataArray addObject:@"NoZuoNoDie"];
  33. [_dataArray addObject:@"YouXianMing"];
  34. [_dataArray addObject:@"LifeIsCoding"];
  35. [_chooseArray addObject:@(NO)];
  36. [_chooseArray addObject:@(NO)];
  37. [_chooseArray addObject:@(NO)];
  38.  
  39. // 初始化tableView
  40. self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
  41. self.tableView.delegate = self;
  42. self.tableView.dataSource = self;
  43. self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
  44. [self.tableView registerClass:[YouXianMingCell class] forCellReuseIdentifier:YouXianMingCellFlag];
  45. [self.view addSubview:self.tableView];
  46.  
  47. }
  48.  
  49. #pragma mark - TableView相关方法
  50. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  51. return _dataArray.count;
  52. }
  53. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  54. YouXianMingCell *cell = [tableView dequeueReusableCellWithIdentifier:YouXianMingCellFlag];
  55. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  56.  
  57. cell.name.text = _dataArray[indexPath.row];
  58.  
  59. if ([_chooseArray[indexPath.row] boolValue] == NO) {
  60. [cell hideIconAnimated:NO];
  61. } else {
  62. [cell showIconAnimated:NO];
  63. }
  64.  
  65. return cell;
  66. }
  67. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  68. YouXianMingCell *cell = (YouXianMingCell *)[tableView cellForRowAtIndexPath:indexPath];
  69.  
  70. [cell showSelectedAnimation];
  71.  
  72. if ([_chooseArray[indexPath.row] boolValue] == NO) {
  73. [_chooseArray replaceObjectAtIndex:indexPath.row withObject:@(YES)];
  74. [cell showIconAnimated:YES];
  75. } else {
  76. [_chooseArray replaceObjectAtIndex:indexPath.row withObject:@(NO)];
  77. [cell hideIconAnimated:YES];
  78. }
  79.  
  80. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  81. }
  82. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  83. return .f;
  84. }
  85.  
  86. @end

测试图片:

核心地方:

UITableView中cell点击的绚丽动画效果的更多相关文章

  1. iOS中UITableView的cell点击事件不触发didSelectRowAtIndexPath(汇总)

    iOS中UITableView的cell点击事件不触发didSelectRowAtIndexPath 首先分析有几种原因,以及相应的解决方法 1.UITableViewCell的userInterac ...

  2. UITableView中cell里的UITextField不被弹出键盘挡住

    UITableView中cell里的UITextField不被弹出键盘挡住 本人视频教程系类   iOS中CALayer的使用 效果如下: 源码: EditCell.h 与 EditCell.m // ...

  3. 如何获取UITableView中cell的frame值

    如何获取UITableView中cell的frame值 这个可以用来处理UITableView弹出键盘的问题 本人视频教程系类   iOS中CALayer的使用 效果: 源码: // // ViewC ...

  4. 用适配器模式处理复杂的UITableView中cell的业务逻辑

    用适配器模式处理复杂的UITableView中cell的业务逻辑 适配器是用来隔离数据源对cell布局影响而使用的,cell只接受适配器的数据,而不会与外部数据源进行交互. 源码: ModelCell ...

  5. 神奇的canvas——点与线绘制的绚丽动画效果

    代码地址如下:http://www.demodashi.com/demo/11636.html 前言 之前在某网站上看到了一个canvas绘制的动画效果,虽然组成的元素很简单,只有点和线,但是视觉效果 ...

  6. 在 jQuery 中使用滑入滑出动画效果,实现二级下拉导航菜单的显示与隐藏效果

    查看本章节 查看作业目录 需求说明: 在 jQuery 中使用滑入滑出动画效果,实现二级下拉导航菜单的显示与隐藏效果 用户将光标移动到"最新动态页"或"帮助查询" ...

  7. 解决UITableView中Cell重用机制导致内容出错的方法总结

    UITableView继承自UIScrollview,是苹果为我们封装好的一个基于scroll的控件.上面主要是一个个的 UITableViewCell,可以让UITableViewCell响应一些点 ...

  8. ios UITableView中Cell重用机制导致内容重复解决方法

    UITableView继承自UIScrollview,是苹果为我们封装好的一个基于scroll的控件.上面主要是一个个的 UITableViewCell,可以让UITableViewCell响应一些点 ...

  9. iOS - UITableView中Cell重用机制导致Cell内容出错的解决办法

    "UITableView" iOS开发中重量级的控件之一;在日常开发中我们大多数会选择自定Cell来满足自己开发中的需求, 但是有些时候Cell也是可以不自定义的(比如某一个简单的 ...

随机推荐

  1. Redis笔记(二):Redis数据类型

    Redis 数据类型 Redis支持五种数据类型:string(字符串),hash(哈希),list(列表),set(集合)及zset(sorted set:有序集合). String(字符串) st ...

  2. 7-nginx-keepalived配置主从双击热备

    nginx的高可用解决方案 keepalive 是 VRRP 协议的完美实现, 通过vip(虚拟ip)来实现主从双击热备, 自动切换的高可用方案, nginx的主从是通过keepalived实现的 通 ...

  3. C#的OpenFileDialog的简单用法

    1.OpenFileDialog 中文名字叫做 打开文件对话框 OpenFileDialog的效果如图: private void btnSelectFile_Click(object sender, ...

  4. WPF多路绑定

    WPF多路绑定 多路绑定实现对数据的计算,XAML:   引用资源所在位置 xmlns:cmlib="clr-namespace:CommonLib;assembly=CommonLib&q ...

  5. 编写代码:ATM的登陆界面(用户验证、主菜单的选择) 查询-- 存款-- 取款-- 退出

    #include <stdio.h>#include <windows.h>int main (void){    int password,one,two,money1=10 ...

  6. django2.1---上下文处理器

    上下文处理器 上下文处理器是可以返回一些数据,在全局模板中都可以使用.比如登录后的用户信息,在很多页面中都需要使用,那么我们可以放在上下文处理器中,就没有必要在每个视图函数中都返回这个对象. 在set ...

  7. ASPxGridView控件的基本属性

    1.//ASPxGridView前台获取行号 <ClientSideEvents RowClick="function(s, e) { s.GetRowKey(e.visibleInd ...

  8. 未能加载“xxx”程序集

    找到程序集名称,去项目文件中查找是否拥有.

  9. c#与IronPython Clojure-clr的调用

    一,python 安装ironpython http://ironpython.net/ 新建控制台程序,引入 IronPython,Microsoft.Scripting 新建xxx.py文件 va ...

  10. Java JDK 配置环境变量

    使用了java也有了两年了,安装了很多次jdk都记不住安装步骤 = =,刚刚又配置了一次,码一下步骤: 1.右击"此电脑" ---> "属性" ----& ...