[控件] TranformFadeView
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的更多相关文章
- JS调用Android、Ios原生控件
在上一篇博客中已经和大家聊了,关于JS与Android.Ios原生控件之间相互通信的详细代码实现,今天我们一起聊一下JS调用Android.Ios通信的相同点和不同点,以便帮助我们在进行混合式开发时, ...
- HTML5 progress和meter控件
在HTML5中,新增了progress和meter控件.progress控件为进度条控件,可表示任务的进度,如Windows系统中软件的安装.文件的复制等场景的进度.meter控件为计量条控件,表示某 ...
- 百度 flash html5自切换 多文件异步上传控件webuploader基本用法
双核浏览器下在chrome内核中使用uploadify总有302问题,也不知道如何修复,之所以喜欢360浏览器是因为帮客户控制渲染内核: 若页面需默认用极速核,增加标签:<meta name=& ...
- JS与APP原生控件交互
"热更新"."热部署"相信对于混合式开发的童鞋一定不陌生,那么APP怎么避免每次升级都要在APP应用商店发布呢?这里就用到了混合式开发的概念,对于电商网站尤其显 ...
- UWP开发必备:常用数据列表控件汇总比较
今天是想通过实例将UWP开发常用的数据列表做汇总比较,作为以后项目开发参考.UWP开发必备知识点总结请参照[UWP开发必备以及常用知识点总结]. 本次主要讨论以下控件: GridView:用于显示数据 ...
- 【踩坑速记】开源日历控件,顺便全面解析开源库打包发布到Bintray/Jcenter全过程(新),让开源更简单~
一.写在前面 自使用android studio开始,就被它独特的依赖方式:compile 'com.android.support:appcompat-v7:25.0.1'所深深吸引,自从有了它,麻 ...
- 对百度WebUploader开源上传控件的二次封装,精简前端代码(两句代码搞定上传)
前言 首先声明一下,我这个是对WebUploader开源上传控件的二次封装,底层还是WebUploader实现的,只是为了更简洁的使用他而已. 下面先介绍一下WebUploader 简介: WebUp ...
- Windows API 设置窗口下控件Enable属性
参考页面: http://www.yuanjiaocheng.net/webapi/create-crud-api-1-put.html http://www.yuanjiaocheng.net/we ...
- VB.NET设置控件和窗体的显示级别
前言:在用VB.NET开发射频检测系统ADS时,当激活已存在的目标MDI子窗体时,被其他子窗体遮住了,导致目标MDI子窗体不能显示. 这个问题怎么解决呢?网上看到一篇帖子VB.NET设置控件和窗体的显 ...
随机推荐
- springweb flux websocket
直接上代码: import org.springframework.stereotype.Component; import org.springframework.web.reactive.sock ...
- java的日期格式化
原博客地址: http://blog.csdn.net/yangbobo1992/article/details/9965105 日期格式: 时间日期标识符: yyyy:年 MM:月 dd:日 hh: ...
- NPOI读取Excel官方demo
关键代码: 读: HSSFWorkbook hssfworkbook; void InitializeWorkbook(string path) { //read the template via F ...
- C#中的序列化和反序列化是什么、有什么作用、使用方法详解
什么是序列化与反序列化??? 序列化和反序列化,我们可能经常会听到,其实通俗一点的解释,序列化就是把一个对象保存到一个文件或数据库字段中去,反序列化就是在适当的时候把这个文件再转化成原来的对象使用. ...
- SQL Server提取字段中的所有数字
今天公司项目中遇到了一个需求,要求提取用户电话号码字段中的所有电话信息. 由于该字段在项目最初设计中没有严格控制数据质量,导致用户在输入时包含了很多非电话的信息,如用户名字等(136 **** *** ...
- Angular2入门教程-2 实现TodoList App
最近在学习<Angular从零到一>(机械工业出版社) 遇到一些问题,书中讲的不明白,在网上找了一些,资源很多,也有很多前人的经验 https://blog.csdn.net/ztguan ...
- EnyimMemcached(64位)使用实例
1.安装:http://www.cnblogs.com/dudu/archive/2009/07/19/1526669.html 2.使用 using Enyim.Caching.Configurat ...
- ibatis中$和#的区别
比如当变量name的类型是Stirng时, $name$ 打印出来的是 张三 #name# 打印出来的是 ‘张三’ $ 的作用实际上是字符串拼接 #用于变量替换 那什么时候用$,什么时候 用 # (1 ...
- 为什么说 LINQ 要胜过 SQL
如果你还没有沉溺于 LINQ,就会想这有啥大惊小怪的.SQL 并没有坏掉,为什么还要对它进行修补呢? 为什么我们还需要另外一种查询语言呢? 流行的说法是 LINQ 同 C#(或者 VB)集成在了一起, ...
- 【 js 片段 】点击空白或者页面其他地方,关闭弹框
$(document).mouseup(function(e){ var _con = $(' 目标区域 '); // 设置目标区域 if(!_con.is(e.target) && ...