将CAGradientLayer用作maskView的遮罩图层
将CAGradientLayer用作maskView的遮罩图层

说明
CAGradientLayer可以用作alpha遮罩,供maskView使用,这两种东西都是非常偏门的东西,但是,偏门不代表功能不强大,我们可以用CAGradientLayer制作出非常牛逼的动画效果,此博文,本人抛砖引玉简易介绍怎么将CAGradientLayer与maskView联系上。后续博文会陆续扩展并写出更好的控件。
只有完美的UI交互效果才能够为功能强大的app锦上添花,本人致力于研究分析苹果开发中那些巨牛逼但却无人问津的冷门特效。
效果图

源码
//
// CAGradientView.h
// AlphaView
//
// Created by YouXianMing on 15/5/4.
// Copyright (c) 2015年 YouXianMing. All rights reserved.
// #import <UIKit/UIKit.h> @interface CAGradientView : UIView @property (nonatomic, strong) NSArray *colors;
@property (nonatomic, strong) NSArray *locations;
@property (nonatomic) CGPoint startPoint;
@property (nonatomic) CGPoint endPoint; - (void)alphaType; @end
//
// CAGradientView.m
// AlphaView
//
// Created by YouXianMing on 15/5/4.
// Copyright (c) 2015年 YouXianMing. All rights reserved.
// #import "CAGradientView.h" @interface CAGradientView () {
CAGradientLayer *_gradientLayer;
} @end @implementation CAGradientView /**
* 修改当前view的backupLayer为CAGradientLayer
*
* @return CAGradientLayer类名字
*/
+ (Class)layerClass {
return [CAGradientLayer class];
} - (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
_gradientLayer = (CAGradientLayer *)self.layer;
}
return self;
} - (void)alphaType {
self.colors = @[[UIColor clearColor], [UIColor blackColor], [UIColor clearColor]];
self.locations = @[@(0.25), @(0.5), @(0.75)];
self.startPoint = CGPointMake(, );
self.endPoint = CGPointMake(, );
} /**
* 重写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
//
// ViewController.m
// AlphaView
//
// Created by YouXianMing on 15/5/4.
// Copyright (c) 2015年 YouXianMing. All rights reserved.
// #import "ViewController.h"
#import "CAGradientView.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; // 加了mask的view
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(, , , )];
imageView.image = [UIImage imageNamed:@"base"];
[self.view addSubview:imageView]; CAGradientView *gradientView = [[CAGradientView alloc] initWithFrame:imageView.bounds];
[gradientView alphaType];
imageView.maskView = gradientView; // 对照组
UIImageView *baseImageView = [[UIImageView alloc] initWithFrame:CGRectMake(, + + , , )];
baseImageView.image = [UIImage imageNamed:@"base"];
[self.view addSubview:baseImageView];
} @end
简易分析

将CAGradientLayer用作maskView的遮罩图层的更多相关文章
- 透明遮罩图层VS高斯模糊滤镜 效果分析
前端流行布局中最常见的弹出图层有popup, 对话框, tooltip等, 他们都使用了新的图层,但是实现办法各不相同, 有 的是通过半通明的黑白图层实现的, 有的是通过滤镜实现的, 我们来研究一下两 ...
- OCiOS开发:CAGradientLayer 渐变色
OCiOS开发:CAGradientLayer 渐变色 CAGradientLayer 简介 CAGradientLayer是CALayer图层类的子类,用于处理渐变色的层结构. CAGradient ...
- 通过CAGradientLayer制作渐变色效果(转)
转载自:http://blog.it985.com/7986.html 看了极客学院的视频之后写的一篇博客,觉得不错,还是作为笔记使用. 简单介绍一下CAGradientLayer吧. Gradien ...
- CSS3裁剪与遮罩解析
一.用途 CSS3裁剪与遮罩(Clipping and Masking)用来隐藏元素的一部分而显示另一部分 二.区别 CSS3裁剪与遮罩(Clipping and Masking)用来隐藏元素的一部分 ...
- CSS3基础(4)——CSS3 渲染属性
一. CSS3 计数器详解 CSS3计数器(CSS Counters)可以允许我们使用CSS对页面中的任意元素进行计数,实现类似于有序列表的功能. 与有序列表相比,它的突出特性在于可以对任意元素 ...
- Flash动画
Flash (交互式矢量图和Web动画标准) Flash是由macromedia公司推出的交互式矢量图和 Web 动画的标准,由Adobe公 司收购.做Flash动画的人被称之为闪客.网页设计者使用 ...
- iOS—Mask属性的使用
Mask属性介绍 Mask平时用的最多的是masksToBounds 吧. 其实除此以外Mask使用场景很多,看完之后你会发现好真是好用的不要不要的... 先来了解下Mask属性到底是什么? Mask ...
- [Quick-x]制作新手引导高亮区域方法之二:裁剪模式
demo下载:https://github.com/chenquanjun/Quick-x-HighlightArea 2.裁剪模式 (1)创建裁剪对象 , , ) --非高亮区域颜色 local b ...
- OpenCV探索之路(十一):轮廓查找和多边形包围轮廓
Canny一类的边缘检测算法可以根据像素之间的差异,检测出轮廓边界的像素,但它没有将轮廓作为一个整体.所以要将轮廓提起出来,就必须将这些边缘像素组装成轮廓. OpenCV中有一个很强大的函数,它可以从 ...
随机推荐
- 回退Ubuntu记录
前言 由于Ubuntu18经常出错,因而决定回退Ubuntu16,下面是记录回退问题及美化,以便以后需要. 问题总结 磁盘挂载 挂载其他磁盘分区时,提示错误"Metadata kept in ...
- elasticsearch(六) 之 elasticsearch优化
目录 elasticsearch 优化 从硬件上 : 从软件上: 从用户使用层 elasticsearch 优化 从硬件上 : 使用SSD 硬盘,解决io导致的瓶颈. 增大内存 但不超过32G(单实例 ...
- 01-python基础
前几天, 觉得python简单的不行, 没有仔细做笔记, 然后今天翻了下前几天看的东西, 还是记下来吧 对于python2.7 和 python3 , 建议使用python3 的模式编程, 然后使用p ...
- 笔记二:python编码详解
一:学习内容 python编码讲解 python编码说明 python中文乱码解决三部曲 二:python编码讲解 1. ASCII编码 美国信息交换标准代码(American Standard Co ...
- jQuery.on() 函数
1.绑定所有的<p>元素// 为所有P元素分别绑定click事件处理函数handler$("p").on("click", handler); 2. ...
- Node.js数据流Stream之Duplex流和Transform流
Duplex流一个很好的例子是TCP套接字连接.需要实现_read(size)和_Write(data,encoding,callback)方法. var stream = require('stre ...
- dev控件ASPxComboBox设置ReadOnly="true"后
dev控件ASPxComboBox设置ReadOnly="true"后,在后台OnCallback事件中赋值前台不显示
- com.mysql.jdbc.MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value:...
在使用mybatis的@Update注解的时候,报了一个这样的错 ### Error updating database. Cause: com.mysql.jdbc.MysqlDataTruncat ...
- java后台工具类-通过交易码获得方法名
import org.apache.log4j.Logger; import net.sf.json.JSONObject; public class GetResultByTransCode { p ...
- ASP.NET MVC传递Model到视图的多种方式总结(二)__关于ViewBag、ViewData和TempData的实现机制与区别
在ASP.NET MVC中,视图数据可以通过ViewBag.ViewData.TempData来访问,其中ViewBag 是动态类型(Dynamic),ViewData 是一个字典型的(Diction ...