1.shapeLayer: 渲染快速,内存占用小,不会被图层边界裁掉(可以在边界之外绘制),不会像素化(当做3D变化如缩放是不会失真)

   CGRect rect = self.containerView.bounds;

    CAShapeLayer *shaper = [CAShapeLayer new];
shaper.backgroundColor = [UIColor yellowColor].CGColor;
shaper.lineWidth = ;
shaper.strokeColor = [UIColor redColor].CGColor;
//单独设置左上,右上圆角
UIRectCorner rcorner = UIRectCornerTopLeft|UIRectCornerTopRight; UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:rcorner cornerRadii:CGSizeMake(, )];
//设置路径
shaper.path = path.CGPath;
// [self.containerView.layer addSublayer:shaper]; //定义父图层的可见区域(这里使父图层的圆角单独设置左上,右上)
self.containerView.layer.mask = shaper;

2.CATextLayer

     CATextLayer *textLayer = [CATextLayer new];
textLayer.frame = self.containerView.bounds;
[self.containerView.layer addSublayer:textLayer]; //设置文本属性
textLayer.foregroundColor = [UIColor blueColor].CGColor;
textLayer.alignmentMode = kCAAlignmentJustified;
textLayer.wrapped = YES; //设置字体
UIFont *font = [UIFont systemFontOfSize:];
CFStringRef fontStrRef = (__bridge CFStringRef)font.fontName;
CGFontRef fontRef = CGFontCreateWithFontName(fontStrRef);
textLayer.font = fontRef;
CFRelease(fontRef);
textLayer.fontSize = font.pointSize;
//设置缩放倍数,防止像素化
textLayer.contentsScale = [UIScreen mainScreen].scale;
//这里也可以设置富文本字符串NSMutableString
textLayer.string = @"on my god we you yao bei rangyizhuier le ma ,zhe me zhen shi de ma ,ai ";

3.CATransformLayer: 不平面化子图层,用于构建3D 形状,如下代码用于构建一个正方体

//产生某个面的子layer
- (CALayer*)faceWithTransform:(CATransform3D)transform{
CALayer *layer = [CALayer layer]; layer.frame = CGRectMake(-, -, , ); layer.backgroundColor = [UIColor colorWithRed:rand()/(double)INT_MAX green:rand()/(double)INT_MAX blue:rand()/(double)INT_MAX alpha:].CGColor;
layer.transform = transform; return layer;
}
- (CALayer*)cubeWithTransform:(CATransform3D)transform{
CATransformLayer *cubeLayer = [CATransformLayer layer];
//
CATransform3D ct = CATransform3DMakeTranslation(, , );
[cubeLayer addSublayer:[self faceWithTransform:ct]]; //
ct = CATransform3DMakeTranslation(, , );
ct = CATransform3DRotate(ct, M_PI_2, , , );
[cubeLayer addSublayer:[self faceWithTransform:ct]]; //
ct = CATransform3DMakeTranslation(, -, );
ct = CATransform3DRotate(ct, -M_PI_2, , , );
[cubeLayer addSublayer:[self faceWithTransform:ct]];
//
ct = CATransform3DMakeTranslation(, , );
ct = CATransform3DRotate(ct, -M_PI_2, , , );
[cubeLayer addSublayer:[self faceWithTransform:ct]];
//
ct = CATransform3DMakeTranslation(-, , );
ct = CATransform3DRotate(ct, -M_PI_2, , , );
[cubeLayer addSublayer:[self faceWithTransform:ct]];
//
ct = CATransform3DMakeTranslation(, , -);
ct = CATransform3DRotate(ct, M_PI, , , );
[cubeLayer addSublayer:[self faceWithTransform:ct]];
cubeLayer.position = CGPointMake(self.containerView.bounds.size.width/, self.containerView.bounds.size.height/); //运用3D变换
cubeLayer.transform = transform; return cubeLayer; }
- (void)testTransformLayer{
CATransform3D tran = CATransform3DIdentity;
tran.m34 = -1.0/;
//添加透视效果
self.containerView.layer.sublayerTransform = tran; CATransform3D ct2 = CATransform3DIdentity;
ct2 = CATransform3DTranslate(ct2, , , );
ct2 = CATransform3DRotate(ct2, -M_PI_4, , , );
ct2 = CATransform3DRotate(ct2, -M_PI_4, , , ); [self.containerView.layer addSublayer:[self cubeWithTransform:ct2]]; }

4.CAGradientLayer:渐变图层

 CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = self.containerView.bounds;
[self.containerView.layer addSublayer:gradientLayer]; gradientLayer.colors = @[(__bridge id)[UIColor redColor].CGColor,(__bridge id)[UIColor yellowColor].CGColor,(__bridge id)[UIColor greenColor].CGColor];
gradientLayer.startPoint = CGPointMake(, );
gradientLayer.endPoint = CGPointMake(, );
//各个渐变点开始渐变的位置,和colors数组个数必须一致.
gradientLayer.locations = @[@0.0,@0.1,@0.2]

5.CAReplicatorLayer,生成重复的子图层,并未每个图层应用变换

    CAReplicatorLayer *replayer = [CAReplicatorLayer layer];
replayer.frame = self.containerView.bounds;
[self.containerView.layer addSublayer:replayer];
//复制个数
replayer.instanceCount = ; CATransform3D transform = CATransform3DIdentity;
transform = CATransform3DTranslate(transform, , , );
transform = CATransform3DRotate(transform, M_PI/5.0, , , );
transform = CATransform3DTranslate(transform, , -, );
//运用变换
replayer.instanceTransform = transform; //改变下一图层的蓝红通道 ,每个复制的图层颜色不一样
replayer.instanceBlueOffset = -0.1;
replayer.instanceRedOffset = - 0.1; //放一个子图层进去
CALayer *layer = [CALayer layer];
layer.frame = CGRectMake(, , , );
layer.backgroundColor = [UIColor whiteColor].CGColor;
[replayer addSublayer:layer];

产生一个倒影效果(这里自定义一个view用于产生倒影效果):

自定义view,返回指定的图层
+ (Class)layerClass{
return [CAReplicatorLayer class];
}
- (instancetype)init{
if (self = [super init]) {
[self setUp];
}
return self;
}
- (instancetype)initWithFrame:(CGRect)frame{
if (self = [super initWithFrame:frame]) {
[self setUp]; }
return self;
}
- (void)awakeFromNib{
[super awakeFromNib];
[self setUp];
}
- (void)setUp{
CAReplicatorLayer *layer = (CAReplicatorLayer*)self.layer;
layer.instanceCount = ; CATransform3D transform = CATransform3DIdentity; CGSize size = self.bounds.size;
transform = CATransform3DTranslate(transform, 0, size.height+2, 0); /**
y方向倒转
*/
transform = CATransform3DScale(transform, , -, );
layer.instanceTransform = transform;
layer.instanceAlphaOffset = -0.6; }

6.CAEmitterLayer:粒子发散效果

 CAEmitterLayer *emmitLayer = [CAEmitterLayer layer];
emmitLayer.frame = self.containerView.bounds;
[self.containerView.layer addSublayer:emmitLayer];
CGSize size = self.containerView.frame.size; emmitLayer.masksToBounds = true;
//重叠部分效果,kCAEmitterLayerAdditive,重叠部分更亮
emmitLayer.renderMode = kCAEmitterLayerAdditive;
//发散点
emmitLayer.emitterPosition = CGPointMake(size.width/, size.height/); CAEmitterCell *cell =[ CAEmitterCell emitterCell];
//注意图片大小
cell.contents = (__bridge id)[UIImage imageNamed:@"spark.jpg"].CGImage;
cell.birthRate = ;//每秒多少个
cell.lifetime = ; cell.color = [UIColor colorWithRed: green:0.5 blue: alpha:].CGColor;
cell.alphaSpeed = -0.3;
cell.velocity = ;
cell.velocityRange = ;
//发散范围
cell.emissionRange = M_PI*; emmitLayer.emitterCells = @[cell];

7.其他

CAEAGLLayer

CAScrollLayer

CATiledLayer:载入大图

Core Animation笔记(特殊图层)的更多相关文章

  1. Core Animation笔记(动画)

    一.隐式动画 layer默认开启隐式动画 禁用隐式动画 [CATransaction setDisableActions:true]; 设置隐士动画时间 //默认0.25s [CATransactio ...

  2. Core Animation笔记(变换)

    1.仿射变换 CGAffineTransformMakeScale : CGAffineTransformMakeTranslation CGAffineTransformMakeRotation(C ...

  3. Core Animation笔记(- Layer 基本属性)

    一.Layer的基本属性 1. contents 图层内容默认为nil 可以指定一张图片作为内容展示 self.layerView.layer.contents = (__bridge id)imag ...

  4. IOS Core Animation Advanced Techniques的学习笔记(一)

    转载. Book Description Publication Date: August 12, 2013 Core Animation is the technology underlying A ...

  5. IOS Core Animation Advanced Techniques的学习笔记(五)

    第六章:Specialized Layers   类别 用途 CAEmitterLayer 用于实现基于Core Animation粒子发射系统.发射器层对象控制粒子的生成和起源 CAGradient ...

  6. IOS Core Animation Advanced Techniques的学习笔记(四)

    第五章:Transforms   Affine Transforms   CGAffineTransform是二维的     Creating a CGAffineTransform   主要有三种变 ...

  7. Core Animation学习总结

    文件夹: The Layer Beneath The Layer Tree(图层树) The Backing Image(寄宿层) Layer Geometry(图层几何学) Visual Effec ...

  8. iOS 图形图像动画 Core Animation

    //Core Animation #define WeakSelf __weak __typeof(self) weakSelf = self #define StrongSelf __strong ...

  9. iOS开发之Core Animation

    在IOS中如果使用普通的动画则可以使用UIKit提供的动画方式来实现,如果想实现更复杂的效果,则需要使用Core Animation了. 在Core Animation中我们经常使用的是 CABasi ...

随机推荐

  1. Redis和MongoDB的区别以及应用场景

    Redis和MongoDB的区别以及应用场景 项目中用的是MongoDB,但是为什么用其实当时选型的时候也没有太多考虑,只是认为数据量比较大,所以采用MongoDB. 最近又想起为什么用MongoDB ...

  2. Partition-wise join

    什么是“partition-wise join”呢?我们将用一个比喻来解释它的好处. 假设两个人,Logan和Shannon,决定住在一起.如果他们每个人都已经有了自己的住所,他们就会拥有很多你在任何 ...

  3. Windows10环境下 Nginx+ffmpeg自搭服务器制作RTMP直播流

    Windows10环境下 Nginx+ffmpeg自搭服务器制作RTMP直播流学习笔记 所需条件: nginx-rtmp-module(带rtmp模块) ,链接:https://link.jiansh ...

  4. springMvc将对象json返回时自动忽略掉对象中的特定属性的注解方式

    1.注解使用在 类名,接口头上 @JsonIgnoreProperties(value={"comid"}) //希望动态过滤掉的属性 例 @JsonIgnorePropertie ...

  5. 解决VS Code开发Python3语言自动补全功能

    1.打开设置界面 2)使用快捷键组合[Ctrl+Shift+p] . 输入setting,选中首选项的user setting模式设置界面 在打开的User Settings文件界面,搜索:pytho ...

  6. python限定方法参数类型、返回值类型、变量类型等

    typing模块的作用 自python3.5开始,PEP484为python引入了类型注解(type hints) 类型检查,防止运行时出现参数和返回值类型.变量类型不符合. 作为开发文档附加说明,方 ...

  7. Qt编写控件属性设计器11-导入xml

    一.前言 上一篇文章负责把设计好的控件数据导出到了xml文件,本偏文章负责把导出的xml数据文件导入,然后在画布上自动生成对应的控件,Qt内置的xml数据解析功能,非常强大,都封装在QtXml组件中, ...

  8. 基于EasyDarwin开源流媒体服务器框架实现EasyNVR H5无插件直播流媒体服务器方案

    背景分析 在之前的一篇博客<web无插件播放RTSP摄像机方案,拒绝插件,拥抱H5!>中,描述了实现一套H5无插件直播方案的各个组件的参考建议,又在博客<EasyNVR H5流媒体服 ...

  9. 一起学习epoll

    epoll 是Linux内核中的一种可扩展IO事件处理机制,最早在 Linux 2.5.44内核中引入,可被用于代替POSIX select 和 poll 系统调用,并且在具有大量应用程序请求时能够获 ...

  10. [LeetCode] 70. Climbing Stairs 爬楼梯

    You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...