美文网首页
CALayer官方文档

CALayer官方文档

作者: lixiaoshuai | 来源:发表于2016-08-13 22:13 被阅读28次

(直接继承于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属性。

相关文章

网友评论

      本文标题:CALayer官方文档

      本文链接:https://www.haomeiwen.com/subject/sgcysttx.html