一. 创建图层继承于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. [html]HTML <form> 标签的 enctype 属性

  2. Linq知识小结

    Linq语法小结:有两种形式的语法可供我们在写Linq查询时使用,分别是“查询语法”.“方法语法”.1)先看个列子,有个直观认识     int[] arr = { 12, 2,45,34,23,18 ...

  3. 海量Office文档搜索

    知识管理系统Data Solution研发日记之十 海量Office文档搜索   经过前面两篇文章的介绍,<分享制作精良的知识管理系统 博客备份程序 Site Rebuild>和<分 ...

  4. view 与layer

      文章出处:http://blog.csdn.net/iukey 一.添加 Quartz Core 框架 要使用 Quartz Core 框架,你需要将其添加到你的工程中 . 然后  #import ...

  5. android图片处理方法(不断收集中)

    //压缩图片大小 public static Bitmap compressImage(Bitmap image) { ByteArrayOutputStream baos = new ByteArr ...

  6. PHP中获取中英文混合字符串长度[主要是指个数,而不是字符串长度](转)

    今晚在写框架的表单验证类时,需要判断某个字符串长度是否在指定区间内,很自然地,想到了PHP中的strlen函数. $str = 'Hello world!'; echo strlen($str);   ...

  7. Sync FrameWork 文件同步 (源码)

    Sync Framework 是一个功能完善的同步平台,实现了应用程序.服务和设备的协作和脱机访问.Sync Framework 提供了一些可支持在脱机状态下漫游.共享数据和获取数据的技术 和工具.通 ...

  8. 最新 Sublime Text 3 Package Control 安装方法

    相信看到这个帖子的童鞋,一般至少对 Sublime Text 有所了解了,废话不多讲,个人在 ST2 还没用好的时候, Sublime Text 3 又横空出世了,不过现在 ST3 还是 beta 版 ...

  9. Fast portable non-blocking network programming with Libevent--转

    Learning Libevent Chapter 0: About this document Chapter 1: A tiny introduction to asynchronous IO. ...

  10. 修改UILabel的行间距

    在iOS开发中  有时候为了调整一些UI效果  我们需要调整UILabel之间的行间距: contentLabel.text:label上显示的文字内容; 5:label行间距; contentLab ...