将CAGradientLayer当做mask使用
将CAGradientLayer当做mask使用

效果

源码
https://github.com/YouXianMing/Animations
//
// CAGradientView.h
// MaskView
//
// Created by YouXianMing on 16/2/15.
// Copyright © 2016年 YouXianMing. All rights reserved.
// #import <UIKit/UIKit.h> @interface CAGradientView : UIView /**
* CAGradientLayer's colors.
*/
@property (nonatomic, strong) NSArray *colors; /**
* CAGradientLayer's locations.
*/
@property (nonatomic, strong) NSArray *locations; /**
* CAGradientLayer's startPoint.
*/
@property (nonatomic) CGPoint startPoint; /**
* CAGradientLayer's endPoint.
*/
@property (nonatomic) CGPoint endPoint; @end
//
// CAGradientView.m
// MaskView
//
// Created by YouXianMing on 16/2/15.
// Copyright © 2016年 YouXianMing. All rights reserved.
// #import "CAGradientView.h" @interface CAGradientView () { CAGradientLayer *_gradientLayer;
} @end @implementation CAGradientView + (Class)layerClass { return [CAGradientLayer class];
} - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { _gradientLayer = (CAGradientLayer *)self.layer;
} return self;
} #pragma mark - 重写setter,getter方法 @synthesize colors = _colors; - (void)setColors:(NSArray *)colors { _colors = colors; // 将color转换成CGColor
NSMutableArray *cgColors = [NSMutableArray array]; for (UIColor *tmp in colors) { id cgColor = (__bridge id)tmp.CGColor;
[cgColors addObject:cgColor];
} // 设置Colors
_gradientLayer.colors = cgColors;
} - (NSArray *)colors { return _colors;
} @synthesize locations = _locations; - (void)setLocations:(NSArray *)locations { _locations = locations;
_gradientLayer.locations = _locations;
} - (NSArray *)locations { return _locations;
} @synthesize startPoint = _startPoint; - (void)setStartPoint:(CGPoint)startPoint { _startPoint = startPoint;
_gradientLayer.startPoint = startPoint;
} - (CGPoint)startPoint { return _startPoint;
} @synthesize endPoint = _endPoint; - (void)setEndPoint:(CGPoint)endPoint { _endPoint = endPoint;
_gradientLayer.endPoint = endPoint;
} - (CGPoint)endPoint { return _endPoint;
} @end
细节

将CAGradientLayer当做mask使用的更多相关文章
- iOS—Mask属性的使用
Mask属性介绍 Mask平时用的最多的是masksToBounds 吧. 其实除此以外Mask使用场景很多,看完之后你会发现好真是好用的不要不要的... 先来了解下Mask属性到底是什么? Mask ...
- Swift - LineChart绘制折线图
LineChart,就使用Core Graphics和QuartzCore框架中的CAShapeLayer绘制.这样执行效率明显比堆砌UIView的方法效率高--占用资源少,执行快. 看看CALaye ...
- MSAA
多重采样抗锯齿(MultiSampling Anti-Aliasing,簡稱MSAA)是一种特殊的超级采样抗锯齿(SSAA).MSAA首先来自于OpenGL.具体是MSAA只对Z缓存(Z-Buffer ...
- swift:打造你自己的折线图
看到苹果Health里的折线图了吗.我们就是要打造一个这样的折线图.没看过的请看下图. 我们的主题在于折线图本身.其他的包括步数.日平均值等描述类的内容这里就不涉及了. 首先观察,这个图种包含些什么组 ...
- GrabCut--Opencv篇
最近因为工作需要,需要实现一个Grabcut函数.Opencv已经提供此函数,今天把opencv的例程拿出来跑了一下,对于简单的背景实现效果还不错. OpenCV中的GrabCut算法是依据<& ...
- iOS CAShapeLayer、CADisplayLink 实现波浪动画效果
iOS CAShapeLayer.CADisplayLink 实现波浪动画效果 效果图 代码已上传 GitHub:https://github.com/Silence-GitHub/CoreAnima ...
- Unity LayerMask
Unity用int32的每一位表示32个层,int32用二进制有32位,Layers通常被摄像机用来渲染部分场景,和灯光照射部分场景使用.但是它们也可以用来做射线检测时忽略一些collder或Coll ...
- 基于GraphCuts图割算法的图像分割----OpenCV代码与实现
转载请注明出处:http://blog.csdn.net/wangyaninglm/article/details/44151213, 来自:shiter编写程序的艺术 1.绪论 图切割算法是组合图论 ...
- CAShapeLayer的使用[2]
CAShapeLayer的使用[2] CAShapeLayer支持的动画类型有如下这些. ------------------------------------------------------- ...
随机推荐
- VS Code折腾记 - (4) 常用必备插件推荐【前端】
前言 这篇文章只要让你做一些基础的配置,把vscode变得更加顺手: 插件的需求不是一成不变,有些插件我已经移除了..在最新的VSCODE 1.9.1中, 部分以前用插件实现的功能已经集成了,那就没有 ...
- iOS仿安卓手势解锁
界面是一个九宫格的布局.九宫格实现思路. 先确定有多少列 cloum = 3; 计算出每列之间的距离 计算为: CGFloat margin = (当前View的宽度 - 列数 * 按钮的宽度) / ...
- .NetCore 利用Jenkins在 Windows平台下打包发布Angular项目
准备环境 安装Jenkins 首先装node,版本根据实际环境而定(node安装包中包含了npm) 安装一般都配置好了环境变量,检查下如果没有就配置下 Jenkins中安装NPM插件 GIt获取代码 ...
- mavean项目的jar位置的影响
由于项目的数据库需求改变了,有mysql数据库变为oracle的,那么对于项目就是需要改变数据库连接池.这个项目运用了mavean框架,那么下载jar在pom.xml文件中填写就可以了,但是oracl ...
- jQuery事件绑定—on()、bind()与delegate()
啃了一段日子的js相关了,学的过程中发现在jQuery中绑定事件时,有人用bind(),有人用on(),有人用delegate(),还有人用live(),看代码的时候觉得都实现功能了也就掀过去了,只是 ...
- Linux 获取目录中最后一个文件的名字
find /application/docker_hub/logs/fof1private/amount_dev -type l | xargs basename
- form的智能表单
1.智能表单的介绍 其中,(1)中的使用格式使得form不会太臃肿. 2.使用规范 3.新属性 4.举例 二.程序 1.关于邮件的问题 <!DOCTYPE html> <head&g ...
- 2017 JUST Programming Contest 2.0 题解
[题目链接] A - On The Way to Lucky Plaza 首先,$n>m$或$k>m$或$k>n$就无解. 设$p = \frac{A}{B}$,$ans = C_{ ...
- DIM-00014: Cannot open the Windows NT Service Control Manager.
创建Oracle数据库时出错: OPW-00001: Unable to open password-file DIM-00014: Cannot open the Windows NT Servic ...
- Atcoder Grand Contest 010 C - Cleaning 树贪心(伪)
C - Cleaning 题目连接: http://agc010.contest.atcoder.jp/tasks/agc010_c Description There is a tree with ...