一. 创建图层继承于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. BAT及各大互联网公司2014前端笔试面试题:HTML/CSS篇

    BAT及各大互联网公司2014前端笔试面试题:HTML/CSS篇 2014/08/03 · Web前端, 开发 · CSS, HTML, 技术面试 分享到: 188 MongoDB集群之分片技术应用 ...

  2. web开发工具类

    1.日期工具类 import java.text.SimpleDateFormat; import java.util.Date; public class DateUtil { public sta ...

  3. [struts2]jstl标签用法技巧

    1.<c:if test="${var} != null"></c:if> 2. <c:foreach var="singleVar&quo ...

  4. for循环中使用了return

    for循环中使用了return,导致没有循环完毕就结束了整个方法的执行.

  5. uLua学习笔记(一):uLua安装及上手

    uLua下载:http://www.ulua.org/ VS2012/2013的用于编写Lua的插件:https://babelua.codeplex.com/或http://unknownworld ...

  6. mongoDB 3.0.3 以上GUI 连接认证问题

    因为项目要用到mongoDB,今天尝试搭建了一下. 首先mongo还是很好装的,yum 或者手动下载都可以,我是yum安装的最新版本的3.0.4. 主要是安装完成之后,需要安装一个GUI管理工具,我尝 ...

  7. 最近看了点C++,分享一下我的进度吧!

    #include <iostream> #include <cmath> #include <iomanip> using namespace std; //Stu ...

  8. Timus 1446. Sorting Hat 分类问题

    At the start of each school year, a very important event happens at Hogwarts. Each of the first-year ...

  9. 封装的分页jq

    (function ($) { $.fn.page = function (options) { var defaults = { divid: "pagediv", count: ...

  10. C# 之 日常积累(二)

    主要涉及(1)数字前补0:(2)去掉decimal类型后边无效的0相关问题. 1.数字前补0 ; ) { returnnumber.ToString(); } else { returnnumber. ...