效果图:

代码部分:

#import "ViewController.h"

@interface ViewController ()

@property (nonatomic, strong) CALayer *imageLayer;
@property (nonatomic, strong) CALayer *maskViewLayer; @property (nonatomic, strong) UIImage *contentImage;
@property (nonatomic, strong) UIImage *maskViewContentImage; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; self.view.backgroundColor = [UIColor blackColor]; self.contentImage = [UIImage imageNamed:@"原始图片"];
self.maskViewContentImage = [UIImage imageNamed:@"maskLayerContents"]; self.imageLayer = [CALayer layer];
self.imageLayer.frame = CGRectMake(, , , );
self.imageLayer.contents = (id)self.contentImage.CGImage; self.maskViewLayer = [CALayer layer];
self.maskViewLayer.frame = CGRectMake(-, -, , );
self.maskViewLayer.contents = (id)self.maskViewContentImage.CGImage; // self.imageLayer的局部区域的显示与否可以通过mask的alpha通道来决定
self.imageLayer.mask = self.maskViewLayer; [self.view.layer addSublayer:self.imageLayer]; } - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
self.maskViewLayer.frame = self.imageLayer.bounds;
}

github:https://github.com/RinpeChen/maskViewInCALayer

最新文章

  1. select两个关联的下拉列表
  2. ACM Coder [T1002] 一直wrong answer,不知道为什么。上代码!就对就对!
  3. php轮流排序,每隔一定的时间轮流进行位置排序,轮询的排行榜:function dataPollingInterval()
  4. coreseek实战(四):php接口的使用,完善php脚本代码
  5. [HDOJ2602]Bone Collector(01背包)
  6. css之clear属性
  7. ImageView 缩放
  8. jquery,js常用特效名称
  9. Android--------Java接口回调
  10. json datetime转换问题
  11. HDU 4442 Physical Examination(贪心)
  12. 如何设置linux的文件和目录的权限
  13. Flash TextField selectable bug block TextEvent.Link solution
  14. 关于ajax 返回值验证问题
  15. ubuntu pip install MySQL-python mysql_config not found
  16. ubuntu-12.04.5下编译openjdk8
  17. SQL记录-PLSQL循环
  18. Linux服务器配置---ntp
  19. 初识Unity Mesh
  20. 通用型正方教务(通杀各版本)存在注入(不需登陆)+获得webshell+提权内网漫游

热门文章

  1. UVA 11389(贪心问题)
  2. Scut 进阶:网络模型拓扑
  3. 使用thumbnailator 时部分图片抛异常
  4. API风格
  5. asp.net framework identity 学习笔记
  6. 台积电16nm工艺为什么好过三星14nm
  7. 《how to design programs》14章 再论自引用数据
  8. 设计模式(一): abstract factory抽象工厂模式 -- 创建型模式
  9. SQL Standard Based Hive Authorization(基于SQL标准的Hive授权)
  10. Centos6.x/Oracle11G 自动化静默安装配置脚本