将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使用的更多相关文章

  1. iOS—Mask属性的使用

    Mask属性介绍 Mask平时用的最多的是masksToBounds 吧. 其实除此以外Mask使用场景很多,看完之后你会发现好真是好用的不要不要的... 先来了解下Mask属性到底是什么? Mask ...

  2. Swift - LineChart绘制折线图

    LineChart,就使用Core Graphics和QuartzCore框架中的CAShapeLayer绘制.这样执行效率明显比堆砌UIView的方法效率高--占用资源少,执行快. 看看CALaye ...

  3. MSAA

    多重采样抗锯齿(MultiSampling Anti-Aliasing,簡稱MSAA)是一种特殊的超级采样抗锯齿(SSAA).MSAA首先来自于OpenGL.具体是MSAA只对Z缓存(Z-Buffer ...

  4. swift:打造你自己的折线图

    看到苹果Health里的折线图了吗.我们就是要打造一个这样的折线图.没看过的请看下图. 我们的主题在于折线图本身.其他的包括步数.日平均值等描述类的内容这里就不涉及了. 首先观察,这个图种包含些什么组 ...

  5. GrabCut--Opencv篇

    最近因为工作需要,需要实现一个Grabcut函数.Opencv已经提供此函数,今天把opencv的例程拿出来跑了一下,对于简单的背景实现效果还不错. OpenCV中的GrabCut算法是依据<& ...

  6. iOS CAShapeLayer、CADisplayLink 实现波浪动画效果

    iOS CAShapeLayer.CADisplayLink 实现波浪动画效果 效果图 代码已上传 GitHub:https://github.com/Silence-GitHub/CoreAnima ...

  7. Unity LayerMask

    Unity用int32的每一位表示32个层,int32用二进制有32位,Layers通常被摄像机用来渲染部分场景,和灯光照射部分场景使用.但是它们也可以用来做射线检测时忽略一些collder或Coll ...

  8. 基于GraphCuts图割算法的图像分割----OpenCV代码与实现

    转载请注明出处:http://blog.csdn.net/wangyaninglm/article/details/44151213, 来自:shiter编写程序的艺术 1.绪论 图切割算法是组合图论 ...

  9. CAShapeLayer的使用[2]

    CAShapeLayer的使用[2] CAShapeLayer支持的动画类型有如下这些. ------------------------------------------------------- ...

随机推荐

  1. MySQL一问一答

    一.问:如果有一张表,里面有个字段为id的自增主键,当已经向表里面插入了10条数据之后,删除了id为8,9,10的数据,再把mysql重启,之后再插入一条数据,那么这条数据的id值应该是多少,是8,还 ...

  2. input onchange事件

    //输入帐号,默认赋值给员工电话和后台登录帐号$('#mobile_phone_').bind('input propertychange', function() { var phone = $(' ...

  3. Codeforces 348B - Apple Tree

    348B - Apple Tree 我们设最后答案为 x , 我们我们就能用x表示出所有节点下面的苹果个数, 然后用叶子节点求lcm, 取最大的可行解. #include<bits/stdc++ ...

  4. 少走弯路,一个老程序猿谈PHP职业发展规划

    PHP是一个使用者非常多的开发语言,但在每个领域里的开发侧重点有所不同互联网方面,在稳定的基础上,更注重性能.高并发,高负载的处理. PHP职业发展规划一般有三条路线,一条技能专精发展路线.另两条,是 ...

  5. sonarQube代码管理工具

    第一步:安装环境:jdk 1.8   idea  mysql5.6以上  sonarqube5.6.6 第二歩:下载好sonarqube后,解压打开bin目录,启动相应OS目录下的StartSonar ...

  6. 【Ray Tracing The Next Week 超详解】 光线追踪2-1

     Preface 博主刚放假回家就进了医院,今天刚完事儿,来续写第二本书  Ready 我们来总结一下上一本书的笔记中我们的一些规定 1. 数学表达式 我们采用小写粗黑体代表向量,大写粗黑体代表矩阵, ...

  7. 什么是 "use strict"? 使用它的好处和坏处分别是什么?

    ECMAscript 5添加了第二种运行模式:"严格模式"(strict mode).顾名思义,这种模式使得Javascript在更严格的条件下运行. 设立"严格模式&q ...

  8. netty-socketio 示例代码

    socket.io是一个不错的websocket项目,github上有它的java实现:netty-socketio 及 示例项目 netty-socketio-demo,基本上看看demo示例项目就 ...

  9. 性能优化:使用SparseArray代替HashMap<Integer,Object>(转)

    HashMap是java里比较常用的一个集合类,我比较习惯用来缓存一些处理后的结果.最近在做一个Android项目,在代码中定义这样一个变量,实例化时,Eclipse却给出了一个 performanc ...

  10. DELPHI - How to use opendialog1 for choosing a folder? TOpenDialog, TFileOpenDialog

    DELPHI - How to use opendialog1 for choosing a folder? On Vista and up you can show a more modern lo ...