图片碎片化mask动画
图片碎片化mask动画
效果
源码
https://github.com/YouXianMing/Animations
//
// TransformFadeViewController.m
// Animations
//
// Created by YouXianMing on 15/11/17.
// Copyright © 2015年 YouXianMing. All rights reserved.
// #import "TransformFadeViewController.h"
#import "TranformFadeView.h"
#import "GCD.h" typedef enum : NSUInteger { TYPE_ONE,
TYPE_TWO, } EType; @interface TransformFadeViewController () @property (nonatomic, strong) TranformFadeView *tranformFadeViewOne;
@property (nonatomic, strong) TranformFadeView *tranformFadeViewTwo; @property (nonatomic, strong) GCDTimer *timer;
@property (nonatomic) EType type; @property (nonatomic, strong) NSArray *images;
@property (nonatomic) NSInteger count; @end @implementation TransformFadeViewController - (void)viewDidLoad { [super viewDidLoad];
} - (void)setup { [super setup]; self.images = @[[UIImage imageNamed:@""],
[UIImage imageNamed:@""],
[UIImage imageNamed:@""],
[UIImage imageNamed:@""],
[UIImage imageNamed:@""]]; // 图片1
self.tranformFadeViewOne = [[TranformFadeView alloc] initWithFrame:self.view.bounds];
self.tranformFadeViewOne.contentMode = UIViewContentModeScaleAspectFill;
self.tranformFadeViewOne.image = [self currentImage];
self.tranformFadeViewOne.verticalCount = ;
self.tranformFadeViewOne.horizontalCount = ;
self.tranformFadeViewOne.center = self.view.center;
[self.tranformFadeViewOne buildMaskView]; self.tranformFadeViewOne.fadeDuradtion = .f;
self.tranformFadeViewOne.animationGapDuration = 0.1f; [self.view addSubview:self.tranformFadeViewOne]; // 图片2
self.tranformFadeViewTwo = [[TranformFadeView alloc] initWithFrame:self.view.bounds];
self.tranformFadeViewTwo.contentMode = UIViewContentModeScaleAspectFill;
self.tranformFadeViewTwo.verticalCount = ;
self.tranformFadeViewTwo.horizontalCount = ;
self.tranformFadeViewTwo.center = self.view.center;
[self.tranformFadeViewTwo buildMaskView]; self.tranformFadeViewTwo.fadeDuradtion = .f;
self.tranformFadeViewTwo.animationGapDuration = 0.1f; [self.view addSubview:self.tranformFadeViewTwo];
[self.tranformFadeViewTwo fadeAnimated:YES]; // timer
self.timer = [[GCDTimer alloc] initInQueue:[GCDQueue mainQueue]];
[self.timer event:^{ if (self.type == TYPE_ONE) { self.type = TYPE_TWO; [self.view sendSubviewToBack:self.tranformFadeViewTwo];
self.tranformFadeViewTwo.image = [self currentImage];
[self.tranformFadeViewTwo showAnimated:NO];
[self.tranformFadeViewOne fadeAnimated:YES]; } else { self.type = TYPE_ONE; [self.view sendSubviewToBack:self.tranformFadeViewOne];
self.tranformFadeViewOne.image = [self currentImage];
[self.tranformFadeViewOne showAnimated:NO];
[self.tranformFadeViewTwo fadeAnimated:YES];
} } timeIntervalWithSecs:];
[self.timer start];
} - (UIImage *)currentImage { self.count = ++self.count % self.images.count; return self.images[self.count];
} @end
//
// TranformFadeView.h
// TransformationFadeView
//
// Created by XianMingYou on 15/4/16.
// Copyright (c) 2015年 XianMingYou. All rights reserved.
// #import <UIKit/UIKit.h> @interface TranformFadeView : UIView /**
* Image显示方式
*/
@property (nonatomic) UIViewContentMode contentMode; /**
* 要显示的相片
*/
@property (nonatomic, strong) UIImage *image; /**
* 垂直方向方块的个数
*/
@property (nonatomic) NSInteger verticalCount; /**
* 水平的个数
*/
@property (nonatomic) NSInteger horizontalCount; /**
* 开始构造出作为mask用的view
*/
- (void)buildMaskView; /**
* 渐变动画的时间
*/
@property (nonatomic) NSTimeInterval fadeDuradtion; /**
* 两个动画之间的时间间隔
*/
@property (nonatomic) NSTimeInterval animationGapDuration; /**
* 开始隐藏动画
*
* @param animated 是否执行动画
*/
- (void)fadeAnimated:(BOOL)animated; /**
* 开始显示动画
*
* @param animated 时候执行动画
*/
- (void)showAnimated:(BOOL)animated; @end
//
// TranformFadeView.m
// TransformationFadeView
//
// Created by XianMingYou on 15/4/16.
// Copyright (c) 2015年 XianMingYou. All rights reserved.
// #import "TranformFadeView.h" #define STATR_TAG 0x19871220 @interface TranformFadeView () /**
* 图片
*/
@property (nonatomic, strong) UIImageView *imageView; /**
* 所有的maskView
*/
@property (nonatomic, strong) UIView *allMaskView; /**
* maskView的个数
*/
@property (nonatomic) NSInteger maskViewCount; /**
* 存储maskView的编号
*/
@property (nonatomic, strong) NSMutableArray *countArray; @end @implementation TranformFadeView /**
* 初始化并添加图片
*
* @param frame frame值
*/
- (void)initImageViewWithFrame:(CGRect)frame { self.imageView = [[UIImageView alloc] initWithFrame:frame];
self.imageView.layer.masksToBounds = YES;
[self addSubview:self.imageView];
} - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { [self initImageViewWithFrame:self.bounds];
} return self;
} - (void)buildMaskView { // 如果没有,就返回空
if (self.horizontalCount < || self.verticalCount < ) { return;
} // 承载所有的maskView
self.allMaskView = [[UIView alloc] initWithFrame:self.bounds];
self.maskView = self.allMaskView; // 计算出每个view的尺寸
CGFloat height = self.frame.size.height;
CGFloat width = self.frame.size.width;
CGFloat maskViewHeight = self.verticalCount <= ? height : (height / self.verticalCount);
CGFloat maskViewWidth = self.horizontalCount <= ? width : (width / self.horizontalCount); // 用以计数
int count = ; // 先水平循环,再垂直循环
for (int horizontal = ; horizontal < self.horizontalCount; horizontal++) { for (int vertical = ; vertical < self.verticalCount; vertical++) { CGRect frame = CGRectMake(maskViewWidth * horizontal,
maskViewHeight * vertical,
maskViewWidth,
maskViewHeight); UIView *maskView = [[UIView alloc] initWithFrame:frame];
maskView.frame = frame;
maskView.tag = STATR_TAG + count;
maskView.backgroundColor = [UIColor blackColor]; [self.allMaskView addSubview:maskView]; count++;
}
} self.maskViewCount = count; // 存储
self.countArray = [NSMutableArray array];
for (int i = ; i < self.maskViewCount; i++) { [self.countArray addObject:@(i)];
}
} /**
* 策略模式一
*
* @param inputNumber 输入
*
* @return 输出
*/
- (NSInteger)strategyNormal:(NSInteger)inputNumber { NSNumber *number = self.countArray[inputNumber];
return number.integerValue;
} - (void)fadeAnimated:(BOOL)animated { if (animated == YES) { for (int i = ; i < self.maskViewCount; i++) { UIView *tmpView = [self maskViewWithTag:[self strategyNormal:i]];
[UIView animateWithDuration:(self.fadeDuradtion <= .f ? .f : self.fadeDuradtion)
delay:i * (self.animationGapDuration <= .f ? 0.2f : self.animationGapDuration)
options:UIViewAnimationOptionCurveLinear
animations:^{ tmpView.alpha = .f; } completion:^(BOOL finished) { }];
} } else { for (int i = ; i < self.maskViewCount; i++) { UIView *tmpView = [self maskViewWithTag:i];
tmpView.alpha = .f;
}
}
} - (void)showAnimated:(BOOL)animated { if (animated == YES) { for (int i = ; i < self.maskViewCount; i++) { UIView *tmpView = [self maskViewWithTag:[self strategyNormal:i]]; [UIView animateWithDuration:(self.fadeDuradtion <= .f ? .f : self.fadeDuradtion)
delay:i * (self.animationGapDuration <= .f ? 0.2f : self.animationGapDuration)
options:UIViewAnimationOptionCurveLinear
animations:^{ tmpView.alpha = .f;
} completion:^(BOOL finished) { }];
} } else { for (int i = ; i < self.maskViewCount; i++) { UIView *tmpView = [self maskViewWithTag:i];
tmpView.alpha = .f;
}
}
} /**
* 根据tag值获取maskView
*
* @param tag maskView的tag值
*
* @return tag值对应的maskView
*/
- (UIView *)maskViewWithTag:(NSInteger)tag { return [self.maskView viewWithTag:tag + STATR_TAG];
} #pragma mark - setter & getter.
@synthesize contentMode = _contentMode;
- (void)setContentMode:(UIViewContentMode)contentMode { _contentMode = contentMode;
self.imageView.contentMode = contentMode;
} - (UIViewContentMode)contentMode { return _contentMode;
} @synthesize image = _image;
- (void)setImage:(UIImage *)image { _image = image;
self.imageView.image = image;
} - (UIImage *)image { return _image;
} @end
细节
使用的时候动态切换图片就可以了,实际上只需要创建出2个view.
图片碎片化mask动画的更多相关文章
- 一个使用openGL渲染的炫丽Android动画库二(碎片化曲面动画)
续一个使用openGL渲染的炫丽Android动画库 MagicSurfaceView v1.1.0发布, 新增碎片化曲面动画 地址:https://github.com/gplibs/android ...
- 用 Core Animation 实现图片的碎片化
用 Core Animation 实现图片的碎片化 参考书籍: 效果如下: 原理其实非常简单哦:). 1. 创建一个CALayer,使用其 contents 属性来装载一张图片(获取图片的CGImag ...
- 腾讯优测优分享 | Android碎片化问题小结——关于闪光灯的那些事儿
腾讯优测是专业的android自动化测试平台,拥有上千款真机,彻底解决android碎片化问题! 这里我要说的不是闪光灯的硬件特征,也不是说底层驱动的原理,我只是跟大家聊一聊在项目中遇到的一些关于闪光 ...
- Android学习笔记(四)之碎片化Fragment实现仿人人客户端的侧边栏
其实一种好的UI布局,可以使用户感到更加的亲切与方便.最近非常流行的莫过于侧边栏了,其实我也做过很多侧边栏的应用,但是那些侧边栏的使用我 都不是很满意,现在重新整理,重新写了一个相对来说我比较满意的侧 ...
- jQuery css3鼠标悬停图片显示遮罩层动画特效
jQuery css3鼠标悬停图片显示遮罩层动画特效 效果体验:http://hovertree.com/texiao/jquery/39/ 效果图: 源码下载:http://hovertree.co ...
- Atitit 图像处理 灰度图片 灰度化的原理与实现
Atitit 图像处理 灰度图片 灰度化的原理与实现 24位彩色图与8位灰度图 首先要先介绍一下24位彩色图像,在一个24位彩色图像中,每个像素由三个字节表示,通常表示为RGB.通常,许多24位彩色图 ...
- [No000034]知乎-长期接收碎片化知识有什么弊端?
你所接受的一切信息,构成了你的思维方式. 所以,长期接受碎片信息的后果,就是让你的思维变得狭隘,难以进行复杂的思考. 碎片信息通常具备这样的特征: •它们往往是一些事实的集合而非逻辑 •它们往往大量简 ...
- HTML5+javascript实现图片加载进度动画效果
在网上找资料的时候,看到网上有图片加载进度的效果,手痒就自己也写了一个. 图片加载完后,隐藏loading效果. 想看加载效果,请ctrel+F5强制刷新或者清理缓存. 效果预览: 0% // ...
- 程序员MM的自白:磨人小妖精之安卓碎片化
文/腾讯优测 章婉霞 除了crash问题,Android平台的碎片化越来越受到移动开发的关注,且不谈支持Android系统的移动设备早已过万款,屏幕.品牌以及传感器等方面的碎片化问题也困扰着开发者. ...
随机推荐
- 【转】实践最有效的提高Android Studio运行、编译速度方案
原文:https://blog.csdn.net/xwh_1230/article/details/60961723 实践最有效的提高Android Studio运行.编译速度方案 最有效提升Andr ...
- springboot 零xml集成mybatis-plus
工程结构 pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmlns=&quo ...
- Spark(十七)图计算GraphX
一.图概念术语 1.1 基本概念 图是由顶点集合(vertex)及顶点间的关系集合(边edge)组成的一种数据结构. 这里的图并非指代数中的图.图可以对事物以及事物之间的关系建模,图可以用来表示自然发 ...
- Rookey.Frame v1.0 视频教程之三发布-框架核心思想介绍
本期发布视频: (三)Rookey.Frame v1.0框架核心思想 介绍了Rookey.Frame v1.0框架搭建的核心思想,将框架核心思想理解清楚,对框架运行就会得心应手 官方视频教程: htt ...
- 为什么Java中Long类型的比float类型的范围小?
为什么Long类型的比float类型的范围小? 2015-09-15 22:36 680人阅读 评论(0) 收藏 举报 版权声明:本文为博主原创文章,未经博主允许不得转载. 作为一个常识,我们都知道浮 ...
- 初始Winsock编程
1.套接字的创建和关闭 使用套接字之前,必须使用socket函数创建一个套接字,此函数调用成功将返回一个套接字句柄. 1 SOCKET socket( 2 int af, //用来指定套接字使用的地址 ...
- 洛谷P1527 [国家集训队] 矩阵乘法 [整体二分,二维树状数组]
题目传送门 矩阵乘法 题目描述 给你一个N*N的矩阵,不用算矩阵乘法,但是每次询问一个子矩形的第K小数. 输入输出格式 输入格式: 第一行两个数N,Q,表示矩阵大小和询问组数: 接下来N行N列一共N* ...
- C++ 基础 杂类
1.set: 基本上跟map是相同(只有一个键),set是key-value 放在一起,map 是分开的,既然都加key ,所以set<> 的内容不可能有重复的情况出现 example: ...
- nc工具学习
0x00.命令详解 基本使用 想要连接到某处:nc [-options] ip port 绑定端口等待连接:nc -l -p port ip 参数: -e prog 程序重定向,一旦连接,就执行 [ ...
- mmcrfs
mmcrfs command Creates a GPFS™ file system. Synopsis mmcrfs Device {"DiskDesc[;DiskDesc...]&quo ...