版本记录
版本号 | 时间 |
---|---|
V1.0 | 2018.01.17 |
前言
CAShapeLayer类是我们经常用到的类,平时也就用一下其基本用法,但是很少详细的翻出来它的开发文档仔细研究下,下面,我就带领大家详细的研究下这个类,详细的看一下它的用法。
API文档
这个类继承自CALayer,属于QuartzCore
框架的类,下面我们就先看一下它的API。
/* CoreAnimation - CAShapeLayer.h
Copyright (c) 2008-2017, Apple Inc.
All rights reserved. */
#import <QuartzCore/CALayer.h>
NS_ASSUME_NONNULL_BEGIN
/* The shape layer draws a cubic Bezier spline in its coordinate space.
*
* The spline is described using a CGPath object and may have both fill
* and stroke components (in which case the stroke is composited over
* the fill). The shape as a whole is composited between the layer's
* contents and its first sublayer.
*
* The path object may be animated using any of the concrete subclasses
* of CAPropertyAnimation. Paths will interpolate as a linear blend of
* the "on-line" points; "off-line" points may be interpolated
* non-linearly (e.g. to preserve continuity of the curve's
* derivative). If the two paths have a different number of control
* points or segments the results are undefined.
*
* 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, e.g. CoreImage filters, applied to the layer or its
* ancestors may force rasterization in a local coordinate space.)
*
* Note: rasterization may favor speed over accuracy, e.g. pixels with
* multiple intersecting path segments may not give exact results. */
CA_CLASS_AVAILABLE (10.6, 3.0, 9.0, 2.0)
@interface CAShapeLayer : CALayer
/* The path defining the shape to be rendered. If the path extends
* outside the layer bounds it will not automatically be clipped to the
* layer, only if the normal layer masking rules cause that. Upon
* assignment the path is copied. Defaults to null. Animatable.
* (Note that although the path property is animatable, no implicit
* animation will be created when the property is changed.) */
@property(nullable) CGPathRef path;
/* The color to fill the path, or nil for no fill. Defaults to opaque
* black. Animatable. */
@property(nullable) CGColorRef fillColor;
/* The fill rule used when filling the path. Options are `non-zero' and
* `even-odd'. Defaults to `non-zero'. */
@property(copy) NSString *fillRule;
/* The color to fill the path's stroked outline, or nil for no stroking.
* Defaults to nil. Animatable. */
@property(nullable) CGColorRef strokeColor;
/* These values define the subregion of the path used to draw the
* stroked outline. The values must be in the range [0,1] with zero
* representing the start of the path and one the end. Values in
* between zero and one are interpolated linearly along the path
* length. strokeStart defaults to zero and strokeEnd to one. Both are
* animatable. */
@property CGFloat strokeStart;
@property CGFloat strokeEnd;
/* The line width used when stroking the path. Defaults to one.
* Animatable. */
@property CGFloat lineWidth;
/* The miter limit used when stroking the path. Defaults to ten.
* Animatable. */
@property CGFloat miterLimit;
/* The cap style used when stroking the path. Options are `butt', `round'
* and `square'. Defaults to `butt'. */
@property(copy) NSString *lineCap;
/* The join style used when stroking the path. Options are `miter', `round'
* and `bevel'. Defaults to `miter'. */
@property(copy) NSString *lineJoin;
/* The phase of the dashing pattern applied when creating the stroke.
* Defaults to zero. Animatable. */
@property CGFloat lineDashPhase;
/* The dash pattern (an array of NSNumbers) applied when creating the
* stroked version of the path. Defaults to nil. */
@property(nullable, copy) NSArray<NSNumber *> *lineDashPattern;
@end
/* `fillRule' values. */
CA_EXTERN NSString *const kCAFillRuleNonZero
CA_AVAILABLE_STARTING (10.6, 3.0, 9.0, 2.0);
CA_EXTERN NSString *const kCAFillRuleEvenOdd
CA_AVAILABLE_STARTING (10.6, 3.0, 9.0, 2.0);
/* `lineJoin' values. */
CA_EXTERN NSString *const kCALineJoinMiter
CA_AVAILABLE_STARTING (10.6, 3.0, 9.0, 2.0);
CA_EXTERN NSString *const kCALineJoinRound
CA_AVAILABLE_STARTING (10.6, 3.0, 9.0, 2.0);
CA_EXTERN NSString *const kCALineJoinBevel
CA_AVAILABLE_STARTING (10.6, 3.0, 9.0, 2.0);
/* `lineCap' values. */
CA_EXTERN NSString *const kCALineCapButt
CA_AVAILABLE_STARTING (10.6, 3.0, 9.0, 2.0);
CA_EXTERN NSString *const kCALineCapRound
CA_AVAILABLE_STARTING (10.6, 3.0, 9.0, 2.0);
CA_EXTERN NSString *const kCALineCapSquare
CA_AVAILABLE_STARTING (10.6, 3.0, 9.0, 2.0);
NS_ASSUME_NONNULL_END
Overview
在其坐标空间中绘制三次Bezier样条曲线的图层。
shape是在图层内容和第一个子图层之间合成的。
shape将被绘制反锯齿,并且在可能的情况下将被映射到屏幕空间,然后进行光栅化以保持分辨率的独立性。 但是,应用于图层或其父类的某些图像处理操作(如CoreImage滤镜)可能会强制在本地坐标空间中进行光栅化。
注意:与精度相比,Shape光栅化可能更有利于速度。 例如,具有多个相交路径段的像素可能不会给出确切的结果。
shape layer
在其坐标空间中绘制一个三次贝塞尔样条曲线。
样条曲线使用CGPath
对象进行描述,并可能同时填充和描边组件(在这种情况下描边被合成填充)。 整个形状是在图层之间合成的内容及其第一个子层。
路径对象可以使用任何具体的CAPropertyAnimation
的子类来动画。 路径将作为线性混合插值"on-line"
点; 可以非线性地插入"off-line"
点(例如保持曲线衍生物的连续性)。 如果两个路径有不同的控制数量点或段的结果是不确定的。
Topics
1. Specifying the Shape Path
-
path
- 定义要呈现的形状的路径,可动画。
2. Accessing Shape Style Properties
-
- 用于填充形状路径的颜色,可动画。
-
- 填充形状路径时使用的填充规则。
-
- 指定形状路径的线条样式。
-
- 描边时,虚线图案应用于形状的路径。
-
- 描边时,应用于形状的路径描边阶段,可动画。
-
- 指定形状路径的线条连接样式。
-
- 指定形状路径的线宽,可动画。
-
- 描边形状路径时使用的尖角限制,可动画。
-
- 用于描绘形状路径的颜色,可动画。
-
- 开始描边路径的相对位置,可动画。
-
- 停止描边路径的相对位置,可动画。
3. Constants
-
- 这些常量指定fillRule的可能填充模式。
-
- 这些常量指定描边路径的连接段之间的连接点的形状。 图lineJoin. Figure 1显示了线条连接样式的外观。
-
Line Cap Values
- 这些常量指定描边时开放路径的端点形状。 图 lineCap.Figure 1显示了线帽样式的外观。
后记
下一篇将主要介绍CAShapeLayer的基本使用。