美文网首页
形状图层和复制图层的简单搭配使用

形状图层和复制图层的简单搭配使用

作者: Z了个L | 来源:发表于2017-02-07 11:18 被阅读34次

// ViewController.h
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController


@end


// ViewController.m
#import "ViewController.h"
#import "UIView+Frame.h"

//屏幕宽高
#define screenW [UIScreen mainScreen].bounds.size.width
#define screenH [UIScreen mainScreen].bounds.size.height

@interface ViewController ()

@end

@implementation ViewController

/*
    主要实现思路:
    1.创建形状图层
    2.创建复制图层
    3.创建透明度动画
    4.创建缩放动画
    5.创建动画组把2个动画添加进去
    6.把动画组添加到形状图层
 */
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self setUp];
}

- (void)setUp {

    UIView *animBack = [[UIView alloc] init];
    animBack.width = screenW;
    animBack.height = screenW;
    animBack.center = self.view.center;
    [self.view addSubview:animBack];

    // 形状图层
    CAShapeLayer *shapL = [CAShapeLayer layer];
    shapL.frame = animBack.bounds;
    shapL.fillColor = [UIColor redColor].CGColor;
    shapL.path = [UIBezierPath bezierPathWithOvalInRect:shapL.bounds].CGPath;
//    shapL.path = [UIBezierPath bezierPathWithRect:shapL.bounds].CGPath;
    // 这句代码不加的话,程序一起来,就会出现一个很大的红色的圆
    shapL.opacity = 0;

    // 复制图层
    CAReplicatorLayer *repL = [CAReplicatorLayer layer];
    repL.frame = animBack.bounds;
    // 复制的份数算自己本身一份
    repL.instanceCount = 3;
    // 每一份显示的间隔时间
    repL.instanceDelay = 0.5;
    [animBack.layer addSublayer:repL];
    // 把形状图层添加到复制层中去
    [repL addSublayer:shapL];

    // 添加透明动画
    CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"opacity"];
    anim.fromValue = @(0.3);
    anim.toValue = @(0);

    // 添加放大动画
    CABasicAnimation *anim2  = [CABasicAnimation animationWithKeyPath:@"transform"];
    anim2.fromValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0, 0, 0)];
    anim2.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(1, 1, 0)];

    // 创建动画组
    CAAnimationGroup *groupA = [CAAnimationGroup animation];
    groupA.animations = @[anim, anim2];
    groupA.duration = 3.0;
    groupA.repeatCount = HUGE;
    // 给形状图层添加动画
    [shapL addAnimation:groupA forKey:nil];
}

@end

  • 实现效果:

相关文章

  • 形状图层和复制图层的简单搭配使用

    实现效果:

  • 第五天 图层样式

    (一)图层样式的使用条件: 不能用图层样式的:背景图层能用图层样式的:像素图层,形状图层,图像图层,图层组,文字图...

  • 2020-05-22

    今天学习了图层的应用(包含图层设置、图层类别、视图中可见图层、移动和复制图层),坐标系的简单应用;课后完成老师布置...

  • 图层蒙版&通道

    一、图层蒙版 功能:遮罩一部分效果,保留一部分效果。使用范围:背景图层,像素图层,形状图层,文字图层,图层组。1、...

  • PS快捷键整理

    图层(复制,选择) 复制图层 1 :按下Alt 拖到紧挨着当前图层的下方; 2 : 拖住当前图层到新建图层图标的位...

  • PS小记之如何将一张模糊图片变得清晰(1)

    一、原图 二、Ctrl+J复制一个新图层,位于原始图层上方。 三、对复制的图层使用滤镜,并执行一下步骤“滤镜— 其...

  • [03-PS]光影过度处理

    1.图层复制:复制2个图层,取名为“高频”和“低频” 2.勾选“低频”图层,选择"滤波"-“模糊”-‘“高斯滤波”...

  • PS图层管理与分类

    图层管理 新建图层:cmd+shift+N 图层命名:双击图层 隐藏图层:关掉眼睛 删除图层:del 复制图层:c...

  • PS教程之剪贴蒙版

    剪贴蒙版:在两个相邻的两个图层中,使用上面图层的内容覆盖到下面图层的形状上;即通过使用处于下方图层的现状来限制上方...

  • 【ps教程】之剪贴蒙版的使用和技巧!

    剪贴蒙版:在两个相邻的两个图层中,使用上面图层的内容覆盖到下面图层的形状上;即通过使用处于下方图层的现状来限制上方...

网友评论

      本文标题:形状图层和复制图层的简单搭配使用

      本文链接:https://www.haomeiwen.com/subject/irbpittx.html