zoukankan      html  css  js  c++  java
  • CALayer实现遮罩效果

    #import "ViewController.h"
    
    @interface ViewController ()
    @property(nonatomic,strong)CALayer *imageLayer;
    @property(nonatomic,strong)CALayer *maskLayer;
    @property(nonatomic,strong)UIImage *imageContents;
    @property(nonatomic,strong)UIImage *maskContents;
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
        //获取图片
        self.imageContents=[UIImage imageNamed:@"1"];
        self.maskContents=[UIImage imageNamed:@"2"];
        
        
        //创建图片layer
        self.imageLayer=[CALayer layer];
        self.imageLayer.frame=CGRectMake(50, 50, 200, 200);
        self.imageLayer.contents=(__bridge id)self.imageContents.CGImage;
        [self.view.layer addSublayer:self.imageLayer];
        
        
        //创建出遮罩layer
        self.maskLayer=[CALayer layer];
        self.maskLayer.frame=self.imageLayer.bounds;
        self.maskLayer.contents=(__bridge id)self.maskContents.CGImage;
        
        //给图片layer提供遮罩的layer
        self.imageLayer.mask=self.maskLayer;
        
        //3秒后做做改变maskLayer的Frame动画
        [self performSelector:@selector(layerAnimation) withObject:nil afterDelay:3];
        
    }
    -(void)layerAnimation
    {
        self.maskLayer.frame=CGRectMake(50, 50, 200, 200);
    }
    - (void)didReceiveMemoryWarning
    {
        [super didReceiveMemoryWarning];
        
    }
    
    @end
  • 相关阅读:
    NumPy:数组计算
    Matplotlib模块:绘图和可视化
    量化投资与Python
    vue-cli脚手架(框架)
    vue 之webpack打包工具的使用
    vue之node.js的简单介绍
    es6简单介绍
    ECMAScript 6 入门
    爬虫框架之Scrapy
    angular5使用httpclient时解决跨域问题
  • 原文地址:https://www.cnblogs.com/thbbsky/p/4380109.html
Copyright © 2011-2022 走看看