解决点击cell执行动画导致的重用问题

说明:

动画的细节都是裸露的,并没有封装,靠看官来优化了。

效果:

源码:

https://github.com/YouXianMing/UITableViewSelectedAnimation

核心:

//
// YouXianMingCell.h
// SelectedAnimation
//
// Created by YouXianMing on 15/4/17.
// Copyright (c) 2015年 YouXianMing. All rights reserved.
// #import <UIKit/UIKit.h> @interface YouXianMingCell : UITableViewCell @property (nonatomic, strong) UILabel *name; - (void)showIconAnimated:(BOOL)animated;
- (void)hideIconAnimated:(BOOL)animated; - (void)showSelectedAnimation; @end
//
// YouXianMingCell.m
// SelectedAnimation
//
// Created by YouXianMing on 15/4/17.
// Copyright (c) 2015年 YouXianMing. All rights reserved.
// #import "YouXianMingCell.h" @interface YouXianMingCell () @property (nonatomic, strong) UIImageView *iconView;
@property (nonatomic, strong) UIView *lineView;
@property (nonatomic, strong) UIView *rectView; @end @implementation YouXianMingCell - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) { _rectView = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
_rectView.layer.borderWidth = .f;
_rectView.layer.borderColor = [UIColor grayColor].CGColor;
[self addSubview:_rectView]; // 图标
_iconView = [[UIImageView alloc] initWithFrame:CGRectMake(, , , )];
_iconView.image = [UIImage imageNamed:@"icon"];
_iconView.alpha = .f;
[self addSubview:_iconView]; // 文字
_name = [[UILabel alloc] initWithFrame:CGRectMake(, , , )];
_name.font = [UIFont fontWithName:@"HelveticaNeue-Thin" size:];
_name.textColor = [UIColor grayColor];
[self addSubview:_name]; _lineView = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
_lineView.alpha = .f;
_lineView.backgroundColor = [UIColor redColor];
[self addSubview:_lineView];
} return self;
} - (void)showIconAnimated:(BOOL)animated {
if (animated) {
_iconView.transform = CGAffineTransformMake(, , , , , ); [UIView animateWithDuration:0.5
delay:
usingSpringWithDamping:
initialSpringVelocity:
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
_iconView.alpha = .f;
_iconView.transform = CGAffineTransformMake(, , , , , ); _lineView.alpha = .f;
_lineView.frame = CGRectMake(, , , ); _name.frame = CGRectMake( + , , , ); _rectView.layer.borderColor = [UIColor redColor].CGColor;
_rectView.transform = CGAffineTransformMake(0.8, , , 0.8, , );
_rectView.layer.cornerRadius = .f;
}
completion:^(BOOL finished) { }];
} else {
_iconView.transform = CGAffineTransformMake(, , , , , );
_iconView.alpha = .f; _lineView.alpha = .f;
_lineView.frame = CGRectMake(, , , ); _name.frame = CGRectMake( + , , , ); _rectView.layer.borderColor = [UIColor redColor].CGColor;
_rectView.transform = CGAffineTransformMake(0.8, , , 0.8, , );
_rectView.layer.cornerRadius = .f;
}
} - (void)hideIconAnimated:(BOOL)animated {
if (animated) {
[UIView animateWithDuration:0.5
delay:
usingSpringWithDamping:
initialSpringVelocity:
options:UIViewAnimationOptionCurveEaseInOut
animations:^{
_iconView.alpha = .f;
_iconView.transform = CGAffineTransformMake(0.5, , , 0.5, , ); _lineView.alpha = .f;
_lineView.frame = CGRectMake(, , , ); _name.frame = CGRectMake(, , , ); _rectView.layer.borderColor = [UIColor grayColor].CGColor;
_rectView.transform = CGAffineTransformMake(, , , , , );
_rectView.layer.cornerRadius = ;
}
completion:^(BOOL finished) { }];
} else {
_iconView.alpha = .f; _lineView.alpha = .f;
_lineView.frame = CGRectMake(, , , ); _name.frame = CGRectMake(, , , ); _rectView.layer.borderColor = [UIColor grayColor].CGColor;
_rectView.transform = CGAffineTransformMake(, , , , , );
_rectView.layer.cornerRadius = ;
}
} - (void)showSelectedAnimation {
UIView *tmpView = [[UIView alloc] initWithFrame:CGRectMake(, , , )];
tmpView.backgroundColor = [[UIColor yellowColor] colorWithAlphaComponent:0.30];
tmpView.alpha = .f; [self addSubview:tmpView]; [UIView animateWithDuration:0.20 delay: options:UIViewAnimationOptionCurveEaseIn animations:^{
tmpView.alpha = 0.8f;
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.20 delay:0.1 options:UIViewAnimationOptionCurveEaseOut animations:^{
tmpView.alpha = .f;
} completion:^(BOOL finished) {
[tmpView removeFromSuperview];
}];
}];
} @end

细节:

解决点击cell执行动画导致的重用问题的更多相关文章

  1. 解决点击cell时,UILabel的背景颜色消失的问题

    -(void)setSelected:(BOOL)selected animated:(BOOL)animated{ [super setSelected:selected animated:anim ...

  2. jQuery全选与反选,且解决点击只执行一次的问题

    <html> <head> <script src="jquery-1.11.1.min.js" type="text/javascript ...

  3. JS: javascript 点击事件执行两次js问题 ,解决jquery绑定click事件出现点击一次执行两次问题

    javascript 点击事件执行两次js问题 在JQuery中存在unbind()方法,先解绑再添加点击事件,解决方案为: $(".m-layout-setting").unbi ...

  4. 点击cell动态修改高度动画

    点击cell动态修改高度动画 效果 源码 https://github.com/YouXianMing/Animations // // TapCellAnimationController.m // ...

  5. 滑动cell的时候执行动画效果

    滑动cell的时候执行动画效果 效果图: 源码: // // ViewController.m // AniTab // // Created by XianMingYou on 15/2/26. / ...

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

    UITableView中cell点击的绚丽动画效果 本人视频教程系类   iOS中CALayer的使用 效果图: 源码: YouXianMingCell.h 与 YouXianMingCell.m / ...

  7. (转载)js(jquery)的on绑定点击事件执行两次的解决办法

    js(jquery)的on绑定点击事件执行两次的解决办法—不是事件绑定而是事件冒泡 遇到的问题:jquery中用.on()给页面中新加的元素添加点击事件时,点击事件源,绑定的事件执行两次,这里的ale ...

  8. iOS点击cell查看大图,点击大图还原小图-b

    一.项目需求 用collectionView展示很多照片,点击某个照片,用全屏scrollView无限循环的方式查看图片.点击放大的图片,图片缩小到原先的尺寸. 如图gif1.gif所示,点击中间的图 ...

  9. jQuery使用伪递归重复执行动画

    使用setInterval()来重复执行动画,会因为动画执行过程的时候,setInterval()的时间依然是在走的,所以会导致动画的调用时间不理想,因此只能使用递归来重复执行动画. // 首页LOG ...

随机推荐

  1. 用css实现在横线中间插入文字

    在一些登录或者注册界面中常常可看到,一个大框框上面的横线中有插入文字,大概示意图如下: 这种现象其实是相对位置作用的结果,可以通过相对定位,是某元素恰好出现在div的边框上. position: re ...

  2. Hive文件存储格式和hive数据压缩

    一.存储格式行存储和列存储 二.Hive文件存储格式 三.创建语句和压缩 一.存储格式行存储和列存储 行存储可以理解为一条记录存储一行,通过条件能够查询一整行数据. 列存储,以字段聚集存储,可以理解为 ...

  3. Mahout实战---编写自己的相似度计算方法

    Mahout本身提供了很多的相似度计算方法,如PCC,COS等.但是当需要验证自己想出来的相似度计算公式是否是好的,这时候需要自己实现相似度类.研究了Mahout-core-0.9.jar的源码后,自 ...

  4. ADO调用分页查询存储过程

    一.分页存储过程 ----------使用存储过程编写一个分页查询----------------------- set nocount off --关闭SqlServer消息 --set nocou ...

  5. 使用T4Scaffolding 创建自己的代码生成

    nuget查找引入T4Scaffolding.Core 这个是最低层的,没有其他依赖,当然也没有现成的模板 这个有对EF的依赖,自带了生成DBContext的模板   这个自带了一些mvc的contr ...

  6. 使用CSS进行定位

    CSS中通过使用position属性,有4种不同类型的定位方式,这会影响元素框生成的方式. position属性值的含义: static:静态定位 元素框正常生成.块级元素生成一个矩形框,作为文档流的 ...

  7. ubuntu上安装redis

    1.Redis简要介绍 访问Redis官方网站 https://redis.io/ 上面介绍到 ,redis是开源,BSD许可,高级的key-value存储系统,可以用来存储字符串,哈希结构,链表,集 ...

  8. 【转】HttpServletRequestWrapper 实现xss注入

    这里说下最近项目中我们的解决方案,主要用到commons-lang3-3.1.jar这个包的org.apache.commons.lang3.StringEscapeUtils.escapeHtml4 ...

  9. Spark你需要知道这些

    谈到 Spark,我们总是强调它比 Hadoop 更高效.为什么它可以更高效呢?是因为它优先使用内存存储?还是因为它拥有比 MapReduce 更简单高效的计算模型? 与 Hadoop 作业的区别 我 ...

  10. PHP错误日志和内存查看

    1.通过命令查看服务器上一共开了多少的 php-cgi 进程: ps -fe |grep "php-fpm"|grep "pool"|wc -l 2.查看FPM ...