一. 创建图层继承于CALayer,并在子类实现drawInContext方法

@interface CTLayer : CALayer

@end

@implementation CTLayer
-(void)drawInContext:(CGContextRef)ctx{
   //画一个圆
CGContextSetRGBFillColor(ctx, , , , );
CGContextAddEllipseInRect(ctx, CGRectMake(, , , ));
CGContextFillPath(ctx);
}
@end

在viewcontroller加载视图时,

    CTLayer *layer = [CTLayer layer];
layer.bounds = CGRectMake(, , , );
layer.anchorPoint = CGPointMake(,);
[layer setNeedsDisplay];//显示图层
[self.view.layer addSublayer:layer];

二. 使用代理方式创建

    CTLayer *layer = [CTLayer layer];
layer.bounds = CGRectMake(, , , );
layer.anchorPoint = CGPointMake(,);
layer.delegate = self; //指定代理,该代理可为任意类型
[layer setNeedsDisplay];//显示layer
[self.view.layer addSublayer:layer];

实现代理方法

#pragma mark 代理方法
-(void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx{
CGContextSetRGBFillColor(ctx, , , , );
CGContextAddEllipseInRect(ctx, CGRectMake(, , , ));
CGContextFillPath(ctx);
}

iOS Core Animation学习总结(2)--实现自定义图层的更多相关文章

  1. iOS Core Animation学习总结(1)--CALayer常用属性

    图层是core animation的基础, UIView之所以能显示在屏幕上,靠的是其内部的这个图层,即每个UIView 都有 CALayer,可通过UIView.layer或者[UIView lay ...

  2. iOS Core Animation学习总结(3)--动画的基本类型

    一. CABasicAnimation (基础动画) 移位: CABasicAnimation *animation = [CABasicAnimation animation]; //keyPath ...

  3. 转 iOS Core Animation 动画 入门学习(一)基础

    iOS Core Animation 动画 入门学习(一)基础 reference:https://developer.apple.com/library/ios/documentation/Coco ...

  4. iOS Core Animation 简明系列教程

    iOS Core Animation 简明系列教程  看到无数的CA教程,都非常的难懂,各种事务各种图层关系看的人头大.自己就想用通俗的语言翻译给大家听,尽可能准确表达,如果哪里有问题,请您指出我会尽 ...

  5. iOS - Core Animation 核心动画

    1.UIView 动画 具体讲解见 iOS - UIView 动画 2.UIImageView 动画 具体讲解见 iOS - UIImageView 动画 3.CADisplayLink 定时器 具体 ...

  6. Core Animation学习总结

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

  7. iOS Core Animation 动画 入门学习(一)基础

    reference:https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreAnimation_guide ...

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

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

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

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

随机推荐

  1. 【转】Netty那点事(三)Channel中的Pipeline

    [原文]https://github.com/code4craft/netty-learning/blob/master/posts/ch3-pipeline.md Channel是理解和使用Nett ...

  2. 【23】宁以non-member、non-friend替换member函数

    1.non-member方法与member方法没有本质区别,对于编译器来说,都是non-member方法,因为member方法绑定的对象,会被编译器转化为non-member方法的第一个形参.non- ...

  3. js replace如何实现全部替换

    js中replace默认只替换第一个相关字符,要想实现替换全部相关字符.如下: replace(/*/g, ','); 例如,替换字符串中的\n str.replace(/\n/g, ',');

  4. 46 关于Linux的I/O重定向

    I/O重定向是一个过程,这个过程捕捉一个文件.或命令.或程序.或脚本.甚至代码块(code block)的输出,然后把捕捉到的输出,作为输入发送给另外一个文件.或命令.或程序.或脚本. 1.I/O重定 ...

  5. 安卓模拟器Android SDK Manager 无法获取SDK列表的解决办法

    1.打开运行Android SDK Manager ,Tool菜单,选择Options,打开设置菜单,勾选“Force https://...sources to be fetched using h ...

  6. 基于S7-200的PLC对里程轮(增量式码盘)解码的应用

             解码模块为JC-11:工业增量式码盘 解码模块,接口简单,易于使用. 应用Step7-MicroWIN编程软件,为S7-200PLC设计本编码盘的应用程序.由于编码盘输出的脉冲信号频 ...

  7. Lazy Load 图片延迟加载(转)

    jQuery Lazy Load 图片延迟加载来源 基于 jQuery 的图片延迟加载插件,在用户滚动页面到图片之后才进行加载. 对于有较多的图片的网页,使用图片延迟加载,能有效的提高页面加载速度. ...

  8. 字符编码的故事(ASCII,ANSI,Unicode,Utf-8区别)转载

    http://www.imkevinyang.com/2009/02/字符编解码的故事(ascii,ansi,unicode,utf-8区别).html 很久很久以前,有一群人,他们决定用8个可以开合 ...

  9. html5刮刮卡

    通过Canvas实现的可刮涂层效果. 修改img.src时涂层也会自动适应新图片的尺寸. 修改layer函数可更改涂层样式. 涂层: 可刮效果: 以下是HTML源代码(已增加移动设备支持): 1 2 ...

  10. 2、netlink简介

    Netlink 是一种特殊的 socket,它是 Linux 所特有的,类似于 BSD 中的AF_ROUTE 但又远比它的功能强大,目前在最新的 Linux 内核(2.6.14)中使用netlink ...