CALayer官方文档

(直接继承于NSObject)

The CALayer class manages image-based content and allows you to perform animations on that content. Layers are often used to provide the backing store for views but can also be used without a view to display content. A layer’s main job is to manage the visual content that you provide but the layer itself has visual attributes that can be set, such as a background color, border, and shadow. In addition to managing visual content, the layer also maintains information about the geometry of its content (such as its position, size, and transform) that is used to present that content onscreen. Modifying the properties of the layer is how you initiate animations on the layer’s content or geometry. A layer object encapsulates the duration and pacing of a layer and its animations by adopting the CAMediaTiming protocol, which defines the layer’s timing information.

calayer管理以图像为基础的内容,允许在内容之上进行动画。它经常为视图提供背景。(即使没有视图,它也能够展示内容)它的主要功能事管理可见的内容。而且他也有自己可设置的属性,例如背景色,边界,阴影效果等。除了管理可见内容,它还可以管理内容的几何学的属性(例如位置,大小,和形状矩阵),今儿控制它在屏幕上的显示。可以通过改变涂层的属性进行动画操作。视图通过遵守CAMediaTiming协议,可以控制动画进行之中的时间效果。

Overview

If the layer object was created by a view, the view typically assigns itself as the layer’s delegate automatically, and you should not change that relationship. For layers you create yourself, you can assign a delegate object and use that object to provide the contents of the layer dynamically and perform other tasks. A layer may also have a layout manager object (assigned to the layoutManager property) to manage the layout of subviews separately.

综述

如果涂层是被一个视图类创建,视图会自动将自己设置为涂层的代理属性。而且你不应该改变这种关系。自行创建的涂层属性,你可以设置代理值,动态改变它的内容,执行其它的操作。图层有自己的布局对象管理它的字视图。


CAShapeLayer

The CAShapeLayer class draws a cubic Bezier spline in its coordinate space. The shape is composited between the layer's contents and its first sublayer.

CAShapeLayer类在它的坐标系统中绘制贝赛尔曲线。图形位于涂层的内容和它的第一层子图层之间。

The shape will be drawn antialiased, and whenever possible it will be mapped into screen space before being rasterized to preserve resolution independence. However, certain kinds of image processing operations, such as CoreImage filters, applied to the layer or its ancestors may force rasterization in a local coordinate space.

Note

Shape rasterization may favor speed over accuracy. For example, pixels with multiple intersecting path segments may not give exact results.




1.类的主要功能是可以自己绘制各种各样的曲线构成图形(通过UIBezier的path的属性)

简单🌰:

CAShapeLayer * layer = [CAShapeLayer layer];

layer.backgroundColor = [UIColor redColor].CGColor;

[self.view.layer addSublayer:layer];

layer.strokeColor = [UIColor redColor].CGColor;

//    layer.fillColor = [UIColor yellowColor].CGColor;

UIBezierPath * path = [UIBezierPath bezierPath];

[path moveToPoint:CGPointMake(100, 100)];

[path addLineToPoint:CGPointMake(100, 200)];

[path addQuadCurveToPoint:CGPointMake(200, 200) controlPoint:CGPointMake(320, 568)];

[path closePath];

layer.path = path.CGPath;

注意点:

1.如果曲线没有形成一个完整的闭合的图形,他会自己自动补全

2.给layer 的path赋值时,注意时path的CGPath属性。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,440评论 5 467
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,814评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,427评论 0 330
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,710评论 1 270
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,625评论 5 359
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,014评论 1 275
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,511评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,162评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,311评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,262评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,278评论 1 328
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,989评论 3 316
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,583评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,664评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,904评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,274评论 2 345
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,856评论 2 339

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 9,282评论 0 23
  • 投资成功的核心方法论,简单到令人发指的地步: 低买高卖 没了!没了!!除此之外,真的没有任何其它更为重要,或者同等...
    越来越好伍新国阅读 330评论 0 1
  • 001 见过不要脸的,但没见过这么不要脸的。我们编辑部的人正准备下班吃饭,我不小心把稿子的最后一个符号弄错了,顾...
    凌之烟阅读 251评论 0 0
  • 2计算机组成原理 源码:无法进行运算 反码: 正数--->反码--->不变 负数--->反码--->符号位1不变,...
    sunflower1518阅读 333评论 1 0
  • 看到“失控"两字,“砍手”这个词立马跳到了我面前。是的,我逛街必买东西,而且一买就超标。经常有的没的都爱...
    芝芝1981阅读 173评论 2 2