TranformFadeView

效果图:

源码地址:

https://github.com/YouXianMing/UI-Component-Collection

注意:

maskView是iOS8中新出的,用以简化alpha遮罩的操作,与layer的mask是一回事,想要修改兼容的,请考虑使用layer的mask来满足你的需求.

特点:

* 方块的个数可以自己设定

* 你可以实现你自己的策略来设定渐变消失的方式

核心源码:

//
// 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];
} /* 重写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

需要注意的细节:

[控件] TranformFadeView的更多相关文章

  1. JS调用Android、Ios原生控件

    在上一篇博客中已经和大家聊了,关于JS与Android.Ios原生控件之间相互通信的详细代码实现,今天我们一起聊一下JS调用Android.Ios通信的相同点和不同点,以便帮助我们在进行混合式开发时, ...

  2. HTML5 progress和meter控件

    在HTML5中,新增了progress和meter控件.progress控件为进度条控件,可表示任务的进度,如Windows系统中软件的安装.文件的复制等场景的进度.meter控件为计量条控件,表示某 ...

  3. 百度 flash html5自切换 多文件异步上传控件webuploader基本用法

    双核浏览器下在chrome内核中使用uploadify总有302问题,也不知道如何修复,之所以喜欢360浏览器是因为帮客户控制渲染内核: 若页面需默认用极速核,增加标签:<meta name=& ...

  4. JS与APP原生控件交互

    "热更新"."热部署"相信对于混合式开发的童鞋一定不陌生,那么APP怎么避免每次升级都要在APP应用商店发布呢?这里就用到了混合式开发的概念,对于电商网站尤其显 ...

  5. UWP开发必备:常用数据列表控件汇总比较

    今天是想通过实例将UWP开发常用的数据列表做汇总比较,作为以后项目开发参考.UWP开发必备知识点总结请参照[UWP开发必备以及常用知识点总结]. 本次主要讨论以下控件: GridView:用于显示数据 ...

  6. 【踩坑速记】开源日历控件,顺便全面解析开源库打包发布到Bintray/Jcenter全过程(新),让开源更简单~

    一.写在前面 自使用android studio开始,就被它独特的依赖方式:compile 'com.android.support:appcompat-v7:25.0.1'所深深吸引,自从有了它,麻 ...

  7. 对百度WebUploader开源上传控件的二次封装,精简前端代码(两句代码搞定上传)

    前言 首先声明一下,我这个是对WebUploader开源上传控件的二次封装,底层还是WebUploader实现的,只是为了更简洁的使用他而已. 下面先介绍一下WebUploader 简介: WebUp ...

  8. Windows API 设置窗口下控件Enable属性

    参考页面: http://www.yuanjiaocheng.net/webapi/create-crud-api-1-put.html http://www.yuanjiaocheng.net/we ...

  9. VB.NET设置控件和窗体的显示级别

    前言:在用VB.NET开发射频检测系统ADS时,当激活已存在的目标MDI子窗体时,被其他子窗体遮住了,导致目标MDI子窗体不能显示. 这个问题怎么解决呢?网上看到一篇帖子VB.NET设置控件和窗体的显 ...

随机推荐

  1. php使用date()函数时,提示的警告

    转载:http://www.shangxueba.com/jingyan/121682.html 在用PHP5.3以上的PHP版本时,只要是涉及时间的会报一个: "PHP Warning: ...

  2. haproxy 学习记录

    1.简易安装 make TARGET=linux26 prefix=/usr/local/haproxy install 启动haproxy在sbin目录,其余的在doc目录 2. 配置 hdr_be ...

  3. centos6.5下yum安装mysql5.5

    第一步就是看linu是否安装了mysql,经过rpm -qa|grep mysql查看到centos下安装了mysql5.1,那就开始卸载咯 2 接下来就是卸载mysql5.1了,命令:rpm -e ...

  4. Vuejs中slot实现自定义组件header、footer等

    Vuejs中slot实现自定义组件header.footer等 vue中的slot主要负责内容分发,之前有介绍过slot的内容,具体链接:http://www.cnblogs.com/vipzhou/ ...

  5. clipboard.js实现复制功能

    项目地址:https://github.com/zenorocha/clipboard.js 现代化的“复制到剪切板”插件.不包含 Flash.gzip 压缩后仅 3kb. 为什么使用它 复制文字到剪 ...

  6. bonecp回缩功能实现

    起因 bonecp不具备回缩功能,即连接池持有连接之后,不会主动去释放这些连接(即使这些连接始终处于空闲状态),因此在使用一段时间之后,连接池会达到配置的最大值. 这种方式一定程度上造成了资源的浪费. ...

  7. 微软官方公布的Windows 8.1 Update常用快捷键

    以前用 Windows Server 2008R2,初装Win8.1,感觉最明显的是开关机速度真心快~下面摘录了常用的几个快捷键: Windows 键+D:显示或隐藏桌面 Windows键+X:访问Q ...

  8. 用pymysql操作数据库

    import pymysql # 打开数据库连接 connection = pymysql.connect(host='127.0.0.1', user='root', passwd=', db='s ...

  9. Tomcat启动慢原因之一 At least one JAR was scanned for TLDs yet contained no TLDs

    Tomcat启动时提示: 信息: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging f ...

  10. Git 学习之git 起步(一)

    起步 本章介绍开始使用 Git 前的相关知识.我们会先了解一些版本控制工具的历史背景,然后试着让 Git 在你的系统上跑起来,直到最后配置好,可以正常开始开发工作.读完本章,你就会明白为什么 Git ...