UIBezierPath Class Reference翻译

来源:互联网 发布:淘宝卖家编辑宝贝尺码 编辑:程序博客网 时间:2024/05/29 14:17

UIBezierPath

 

The UIBezierPath class lets you define a path consisting ofstraight and curved line segments and render that path in your custom views.You use this class initially to specify just the geometry for your path. Pathscan define simple shapes such as rectangles, ovals, and arcs or they can definecomplex polygons that incorporate a mixture of straight and curved linesegments. After defining the shape, you can use additional methods of thisclass to render the path in the current drawing context.

通过UIBezierPath你可以定义一条包括直线和曲线的路径,并将此路径添加到你自定义的视图上。首先你可以使用这个类来描述你路径的几何形状。路径可以是简单的矩形、椭圆形和弧形,也可以是使用直线和曲线定义的复杂多边形。在定义完形状以后,你可以使用这个类的其它方法将它绘制到当前的上下文中。


UIBezierPath object combines the geometry of a path withattributes that describe the path during rendering. You set the geometry andattributes separately and can change them independent of one another. Once youhave the object configured the way you want it, you can tell it to draw itselfin the current context. Because the creation, configuration, and rendering processare all distinct steps, Bezier path objects can be reused easily in your code.You can even use the same object to render the same shape multiple times,perhaps changing the rendering

optionsbetween successive drawing calls.

一个UIBezierPath对象包括绘制路径时所定义的几何形状和各种属性。你一个分别设置几何形状和属性值,并且可以单独的修改它们。一旦你配置好了曲线所需的要素,你就可以让它在当前上下文中进行绘制。因为创建,配置,绘制过程都是不同的步骤,Bezier曲线可以方便的进行重用。你甚至可以使用相同的对象多次绘制相同的形状,所需要更改的也许只是修改连续调用时的绘制选项。

 

Youset the geometry of a path by manipulating the path’s current point. When youcreate a new empty path object, the current point is undefined and must be setexplicitly. To move the current point without drawing a segment, you use the moveToPoint: method. All other methods result in the addition of either aline or curve segments to the path. The methods for adding new segments alwaysassume you are starting at the current point and ending at some new point thatyou specify. After adding the segment, the end point of the new segmentautomatically becomes the current point.

你可以通过操作路径的当前点来设置路径的几何形状。当你创建了一个新的空路径对象时,路径的当前点是未设置的,你必须明确设置这个值。使用moveToPoint:方法将当前点移动到路径的起始位置,这个方法不会绘制线段。所有其他的方法都会绘制直线或曲线到当前的路径上。添加新线段的方法都是从当前点开始,终止于你所定义的结束点。在添加完线段后,结束点会自动变成当前点。

 

Asingle Bezier path object can contain any number of open or closed subpaths,where each subpath represents a connected series of path segments. Calling the closePath method closes a subpath by adding a straight line segment fromthe current point to the first point in the subpath. Calling the moveToPoint: method ends the current subpath (withoutclosing it) and sets the starting point of the next subpath. The subpaths of aBezier path object share the same drawing attributes and must be manipulated asa group. To draw subpaths with different attributes, you must put each subpathin its own UIBezierPath object.

一条Bezier路径对象可以包含任意数量的开放或封闭的子路径,每一条子路径都代表了一组可被连接的路径线段。closePath方法将在当前点和子路径中的第一个点之间创建一条直线,从而封闭子路径。调用moveToPoint:方法结束当前的子路径(不封闭)并且设置了吓一跳子路径的起始点。Bezier路径对象的所有子路径共用同一个绘制属性,且必须作为一个族被操作。使用不同的属性绘制子路径,必须将每一个子路径添加到它自己的UIBezierPath对象中。

 

Afterconfiguring the geometry and attributes of a Bezier path, you draw the path inthe current graphics context using the stroke and fill methods. The stroke method traces the outline of the path usingthe current stroke color and the attributes of the Bezier path object.Similarly, the fill method fills in the area enclosed by the pathusing the current fill color. (You set the stroke and fill color using the UIColor class.)

在配置完Bezier路径的几何形状和属性之后,你可以说histrokefill方法在当前的图形环境中绘制路径。Stroke方法使用当前的填充颜色和Bezier路径对象属性对路径的外轮廓进行描边。相似的,fill方法使用当前的填充颜色对路径形成的封闭区域进行填充。(你可以通过UIColor类来设置描边色和填充色。)

 

Inaddition to using a Bezier path object to draw shapes, you can also use it todefine a new clipping region. The addClip method intersects the shape represented by the path object withthe current clipping region of the graphics context. During subsequent drawing,only content that lies within the new intersection region is actually renderedto the graphics context.

使用Bezier路径对象除了可以绘制图形,你也可以使用它来定义裁剪区域。addClip方法可以根据路径对象对当前图形绘制上下文规划裁剪区域。在随后的绘制中,只有位于新的裁剪取悦中的图像才会被绘制出来。

  

Creating a UIBezierPath Object(创建UIBezierPath对象)

+bezierPath

Creates and returns a new UIBezierPath object.(创建并返回一个新的UIBezierPath对象)

Declaration

OBJECTIVE-C

+ (instancetype)bezierPath

ReturnValue

A new empty path object.(返回一个空的path对象)

Availability

Available in iOS 3.2 and later.iOS3.2及以后可用)

 

+ bezierPathWithRect:

Creates and returns a new UIBezierPath object initialized with a rectangularpath.(创建并返回一个使用矩形路径初始化的UIBezierPath对象)

Declaration

OBJECTIVE-C

+ (instancetype)bezierPathWithRect:(CGRect)rect

Parameters

rect

The rectangle describing the path to create.(描述将要创建路径的矩形)

Return Value

A new path object withthe rectangular path.(一个新的使用举行路径的UIbezierPath对象)

Discussion

This method creates a closed subpath bystarting at the origin of rect and adding line segments in a clockwise direction(relative to the default coordinate system).

这个方法从矩形的起点开始按顺时针方向(相对于默认的坐标系统)依次添加线段,创建一个封闭的子路径。

Availability

Available in iOS 3.2 and later.iOS3.2及以后可用)

 

+bezierPathWithOvalInRect:

Creates and returns a new UIBezierPath object initialized with an oval path inscribedin the specified rectangle

创建并返回内接于给定矩形的椭圆路径对象。

Declaration

OBJECTIVE-C

+ (instancetype)bezierPathWithOvalInRect:(CGRect)rect

Parameters

rect

The rectangle in which to inscribe an oval.(椭圆的外接矩形)

Return Value

A new path object withthe oval path.(返回椭圆路径对象)

Discussion

This method creates a closed subpath thatapproximates the oval using a sequence of Bézier curves. The path is created ina clockwise direction (relative to the default coordinate system). If the rect parameter specifies a square, theinscribed path is a circle.

这个方法使用一系列的Bézier曲线创建了一个近似椭圆的形状。这条路径是顺时针方向(相对于默认坐标系)。如果矩形参数是正方形,那么返回的是一个圆形路径对象。

Availability

Available in iOS 3.2 and later.iOS3.2及以后可用)

 

+bezierPathWithRoundedRect:cornerRadius:

Creates and returns a new UIBezierPath object initialized with a roundedrectangular path.

创建并返回一个新的使用圆角矩形进行初始化的UIBezierPath对象。

Declaration

OBJECTIVE-C

+ (instancetype)bezierPathWithRoundedRect:(CGRect)rect
            cornerRadius:(CGFloat)cornerRadius

Parameters

rect

The rectangle that defines the basic shape of the path

定义基础图形路径的矩形

cornerRadius

The radius of each corner oval. A value of 0 results in a rectangle without rounded corners. Values larger than half the rectangle’s width or height are clamped appropriately to half the width or height.

每一个角的弧度。0值表示不使用圆角。大于矩形宽度或高度一般的值将近视登录宽度或高的一半。

Return Value

A new path object withthe rounded rectangular path.(一个新的圆角矩形对象路径)

Discussion

This method creates aclosed subpath, proceeding in a clockwise direction (relative to the defaultcoordinate system) as it creates the necessary line and curve segments.

这个方法沿顺时针方向(相对于默认坐标系统)创建必要的直线段和曲线段以形成一个封闭路径。

 Availability

Available in iOS 3.2 and later.iOS3.2及以后可用)

 

+bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:

Creates and returns a new UIBezierPath object initialized with a roundedrectangular path.

创建并返回一个使用圆角矩形路径初始化的UIBezierPath对象

Declaration

OBJECTIVE-C

+ (instancetype)bezierPathWithRoundedRect:(CGRect)rect
            byRoundingCorners:(UIRectCorner)corners
                  cornerRadii:(CGSize)cornerRadii

Parameters

rect

The rectangle that defines the basic shape of the path.

定义基础形状路径的矩形

corners

A bitmask value that identifies the corners that you want rounded. You can use this parameter to round only a subset of the corners of the rectangle.

一个定义了你所想设置圆角位置的bitmask值(枚举类型,表示了矩形四个角的位置),可以使用这个参数来设置到底矩形的哪一个或哪几个角为圆角。

cornerRadii

The radius of each corner oval. Values larger than half the rectangle’s width or height are clamped appropriately to half the width or height.

每一个圆角的半径,大于矩形宽度和高的一半的值会被近似成矩形宽度或高度的一半。

Return Value

A new path object withthe rounded rectangular path.

返回圆角矩形路径对象

Discussion

This method creates aclosed subpath, proceeding in a clockwise direction (relative to the defaultcoordinate system) as it creates the necessary line and curve segments.

这个方法沿顺时针方向创建必要地直线和曲线段并最终形成封闭的路径。

Availability

Available in iOS 3.2 and later.iOS3.2及以后可用)

 


+bezierPathWithArcCenter:radius:startAngle:endAngle:clockwise:

Creates and returns a new UIBezierPath objectinitialized with an arc of a circle.

创建并返回一个使用圆弧初始化的UIBezierPath对象。

Declaration

OBJECTIVE-C

+ (instancetype)bezierPathWithArcCenter:(CGPoint)center
                radius:(CGFloat)radius
                startAngle:(CGFloat)startAngle
                endAngle:(CGFloat)endAngle
                clockwise:(BOOL)clockwise

Parameters

center

Specifies the center point of the circle (in the current coordinate system) used to define the arc.

设置圆弧的圆心(在当前的坐标系统中)

radius

Specifies the radius of the circle used to define the arc.

设置圆弧的半径

startAngle

Specifies the starting angle of the arc (measured in radians).

设置圆弧的起始角度(弧度值)

endAngle

Specifies the end angle of the arc (measured in radians).

设置圆弧的终止角度(弧度值)

clockwise

The direction in which to draw the arc.

绘制圆弧的方向

Return Value

Anew path object with the specified arc.

返回一个圆弧路径

Discussion

This methodcreates an open subpath. The created arc lies on the perimeter of the specifiedcircle. When drawn in the default coordinate system, the start and end anglesare based on the unit circle shown in Figure 1. For example, specifying astart angle of 0 radians, an end angle of π radians, andsetting the clockwiseparameter to YES draws the bottom half ofthe circle. However, specifying the same start and end angles but settingthe clockwise parameter set to NO draws the top half of thecircle.

这个方法创建了一个开放的路径。被创建的圆弧依赖于特定的圆形。当在默认坐标系系统中绘制时,其实角度和终止角度是基于插图1中所示的单位圆。例如,设置起始角度为0弧度,终止角度为π弧度,clockwiseparameter为YES将绘制下半圆弧。反之,设置相同的起始角度和终止角度,但是clockwiseparameter设置为NO将绘制上半圆弧。

 

Figure 1Angles in the defaultcoordinate system(默认坐标系中的角度)


After calling this method, the current point is set to the pointon the arc at the end angle of the circle.

调用此方法后,当前点将移动到圆弧的终止点上。

Availability

Available iniOS 3.2 and later.iOS3.2及以后可用)

 


+ bezierPathWithCGPath:

Creates and returns a new UIBezierPath objectinitialized with the contents of a Core Graphics path.

创建并返回使用Core Graphics 路径初始化的UIBezierPath对象

Declaration

OBJECTIVE-C

+ (instancetype)bezierPathWithCGPath:(CGPathRef)CGPath

Parameters

CGPath

The Core Graphics path from which to obtain the initial path information. If this parameter isnil, the method raises an exception.

包含原始路径信息的Core Graphics路径。假如这个参数为nil,将会抛出异常。

Return Value

A new path object with the specified path information.

返回包含特定路径信息的UIBezierPath对象

Availability

Available iniOS 3.2 and later.iOS3.2及以后可用)

 


- bezierPathByReversingPath

Creates and returns a new bezier path object with the reversedcontents of the current path.

创建并返回一个和当前路径相反的UIBezierPath对象。

Declaration

OBJECTIVE-C

- (UIBezierPath *)bezierPathByReversingPath

Return Value

A new path object with the same path shape but for which thepath has been created in the reverse direction.

返回和当前路径形状一样,但是以相反方向绘制的图形。

Discussion

Reversing a path does not necessarily change the appearance ofthe path when rendered. Instead, it changes the direction in which pathsegments are drawn. For example, reversing the path of a rectangle (whose linesegments are normally drawn starting at the origin and proceeding in acounterclockwise direction) causes its line segments to be drawn in a clockwisedirection instead. Drawing a reversed path could affect the appearance of afilled pattern, depending on the pattern and the fill rule in use.

反转一个路径不一定改变路径的形状。相反,它改变的是路径绘制的方向。例如,反转一个矩形(其绘制方向为从起始点逆时针方向绘制)将使得它的绘制方向变为顺时针。绘制相反的路径会影响填充模式下地图形外表,取决于填充模式和填充规则。

This method reverses each whole or partial subpath in the pathobject individually.

这个方法在路径对象中单独反转每一个全部或部分子路径。

Availability

Available iniOS 6.0 and later.iOS6.0及以后可用)

 

Constructing a Path(创建路径)

- moveToPoint:

Moves the receiver’s current point to the specified location.

将接受者的当前点移动到指定位置。

Declaration

OBJECTIVE-C

- (void)moveToPoint:(CGPoint)point

Parameters

point

A point in the current coordinate system.

当前坐标系统中的一个点。

Discussion

This methodimplicitly ends the current subpath (if any) and sets the current point to thevalue in the pointparameter.When ending the previous subpath, this method does not actually close thesubpath. Therefore, the first and last points of the previous subpath are notconnected to each other.

这个方法隐式的结束当前的子路径(如果有的话)并且将当前的点设置到point参数指定的位置。当结束之前的子路径时,这个方法并没有真正的关闭子路径。然而,之前子路径的第一个点和最后一个点并不会连接起来。

 

For many path operations, you must call this method beforeissuing any commands that cause a line or curve segment to be drawn.

对许多路径操作而言,你必须在绘制任何直线或曲线之前调用此方法。

Availability

Available iniOS 3.2 and later.iOS3.2及以后可用)

 


- addLineToPoint:

Appends a straight line to the receiver’s path.

添加一条直线到接受者路径中

Declaration

OBJECTIVE-C

- (void)addLineToPoint:(CGPoint)point

Parameters

point

The destination point of the line segment, specified in the current coordinate system.

线段的终点,指定于当前坐标系统。

Discussion

This methodcreates a straight line segment starting at the current point and ending at thepoint specified by the point parameter. After adding the line segment, this method updatesthe current point to the value inpoint.

You must setthe path’s current point (using the moveToPoint: method or through the previous creation of a line or curvesegment) before you call this method. If the path is empty, this method doesnothing.

这个方法将创建一条起始于当前点并终止于point参数指定点的直线。在添加完直线段之后,这个方法将当前点移动到point参数所指定的位置。在调用此方法前你必须设置路径的当前点(使用moveToPoint:方法或则通过之前创建线段或曲线段确定)。加入路径为空,这个方法将什么都不做。

Availability

Available iniOS 3.2 and later.iOS3.2及以后可用)

 

-addArcWithCenter:radius:startAngle:endAngle:clockwise:

Appends an arc to the receiver’s path.

添加一个圆弧到接受者路径中

Declaration

OBJECTIVE-C

- (void)addArcWithCenter:(CGPoint)center
                  radius:(CGFloat)radius
              startAngle:(CGFloat)startAngle
                endAngle:(CGFloat)endAngle
               clockwise:(BOOL)clockwise

Parameters

center

Specifies the center point of the circle (in the current coordinate system) used to define the arc.

指定圆弧的圆心(当前坐标系)

radius

Specifies the radius of the circle used to define the arc.

指定圆弧的半径

startAngle

Specifies the starting angle of the arc (measured in radians).

指定圆弧的起始角度

endAngle

Specifies the end angle of the arc (measured in radians).

指定圆弧的终止角度

clockwise

The direction in which to draw the arc.

圆弧的绘制方向

Discussion

This methodadds the specified arc beginning at the current point. The created arc lies onthe perimeter of the specified circle. When drawn in the default coordinatesystem, the start and end angles are based on the unit circle shown in Figure 1.For example, specifying a start angle of 0 radians, an end angle of π radians, and setting the clockwise parameter to YES draws the bottom half of the circle. However,specifying the same start and end angles but setting the clockwise parameter set to NO draws the top half of the circle.

这个方法创建了一个开放的路径。被创建的圆弧依赖于特定的圆形。当在默认坐标系系统中绘制时,其实角度和终止角度是基于插图1中所示的单位圆。例如,设置起始角度为0弧度,终止角度为π弧度,clockwiseparameter为YES将绘制下半圆弧。反之,设置相同的起始角度和终止角度,但是clockwiseparameter设置为NO将绘制上半圆弧。

 

After calling this method, the current point is set to the pointon the arc at the end angle of the circle.

调用此方法后,当前点将移动到圆弧的终止点上。

 

Availability

Available iniOS 4.0 and later.iOS4.0及以后可用)

 

- addCurveToPoint:controlPoint1:controlPoint2:

 

Appendsa cubic Bézier curve to the receiver’s path.

添加一个三次Bézier(贝塞尔)曲线到接收者路径中

Declaration

OBJECTIVE-C

- (void)addCurveToPoint:(CGPoint)endPoint
          controlPoint1:(CGPoint)controlPoint1
          controlPoint2:(CGPoint)controlPoint2

Parameters

endPoint

The end point of the curve.

曲线的终点

controlPoint1

The first control point to use when computing the curve.

计算曲线时的第一个控制点

controlPoint2

The second control point to use when computing the curve.

计算曲线时的第二个控制点

Discussion

This method appends a cubic Bézier curve from thecurrent point to the end point specified by the endPoint parameter. Thetwo control points define the curvature of the segment. Figure2 shows an approximation of a cubic Bézier curve given a set of initialpoints. The exact curvature of the segment involves a complex mathematicalrelationship between all of the points and is well documented online.

这个方法创建一个从起始点到终点的三次Bézier曲线。两个控制点决定了线段的曲率。插图2展示了一个根据一系列初始点绘制的近似三次Bézier曲线。精确地线段曲率涉及到所有点之间的复杂数学关系,网上有很好的文档来说明。

Figure2A cubic Bézier curve

 

 

You must setthe path’s current point (using the moveToPoint: method or through the previous creation of a line or curvesegment) before you call this method. If the path is empty, this method doesnothing. After adding the curve segment, this method updates the current pointto the value in point.

在调用此方法之前必须设置路径的当前点(使用moveToPoint:方法或者通过之前直线段或者曲线段的创建)。如果路径为空,这个方法什么都不会做。添加完曲线段后,这个方法会将当前点更新为point参数指定的点。

Availability

Available iniOS 3.2 and later.iOS3.2及以后可用)

 


- addQuadCurveToPoint:controlPoint:

Appends a quadratic Bézier curve to the receiver’s path.

在接受者路径中添加二次Bézier曲线。

Declaration

OBJECTIVE-C

- (void)addQuadCurveToPoint:(CGPoint)endPoint
               controlPoint:(CGPoint)controlPoint

Parameters

endPoint

The end point of the curve.

曲线的终止点

controlPoint

The control point of the curve.

曲线的控制点

Discussion

This methodappends a quadratic Bézier curve from the current point to the end pointspecified by theendPoint parameter. The relationships between thecurrent point, control point, and end point are what defines the actual curve. Figure 3 showssome examples of quadratic curves and the approximate curve shape based on somesample points. The exact curvature of the segment involves a complexmathematical relationship between the points and is well documented online.

这个方法会在当前点和endPoint参数指定的终止点之间创建一条二次Bézier曲线。当前点,控制点和终止点之间的关系决定了曲线的形状。插图3展示了一些二次曲线的例子,和基于这些样例点得近视曲线形状。线段的精确曲率设计到点之间复杂的数学关系,这些文档在网络上可以很好的被找到。

Figure 3Quadratic curve examples


You must setthe path’s current point (using the moveToPoint: method or through the previous creation of a line or curvesegment) before you call this method. If the path is empty, this method doesnothing. After adding the curve segment, this method updates the current pointto the value in point.

调用此方法之前你必须设置路径的当前点(使用moveToPoint:方法或者通过之前创建直线或则曲线的方法)。如果这个路径为空,这个方法将什么都不会做。在添加完曲线段之后,这个方法会讲当前点移动到point参数指定的位置。

Availability

Available iniOS 3.2 and later.iOS3.2及以后可用)

 


- closePath

Closes the most recently added subpath.

封闭最近添加的子路径

Declaration

OBJECTIVE-C

- (void)closePath

Discussion

This method closes the current subpath by creating a linesegment between the first and last points in the subpath. This methodsubsequently updates the current point to the end of the newly created linesegment, which is also the first point in the now closed subpath.

这个方法通过直线连接当前子路径的起始点和终点来关闭当前的子路径。随后此方法将会讲当前点更新到新添加直线段的终点,即刚闭合路径的第一个点。

Availability

Available iniOS 3.2 and later.iOS3.2及以后可用)

 


- removeAllPoints

 

Removes all points from the receiver, effectively deleting allsubpaths.

从接收者中移除所有的点,有效删除所有的子路径

Declaration

OBJECTIVE-C

- (void)removeAllPoints

Availability

Available iniOS 3.2 and later.iOS3.2及以后可用)

 


- appendPath:

 

Appends the contents of the specified path object to thereceiver’s path.

添加指定的路径内容到接收者路径中。

Declaration

OBJECTIVE-C

- (void)appendPath:(UIBezierPath *)bezierPath

Parameters

bezierPath

The path to add to the receiver.

添加到接受者中的路径

Discussion

This methodadds the commands used to create the path in bezierPath to the end of the receiver’s path. This method does notexplicitly try to connect the subpaths in the two objects, although theoperations inbezierPath might still cause that effect.

这个方法将参数bezierPath中创建路径的命令添加到接收者路径的最后。虽然参数bezierPath中的操作也许会连接两个对象中的子路径,但是这个方法并没有明确地试图连接两个对象中的子路径。

Availability

Available iniOS 3.2 and later.iOS3.2及以后可用)


CGPath Property

The Core Graphics representation of the path.

路径的Core Graphics表示

Declaration

OBJECTIVE-C

@property(nonatomicCGPathRef CGPath

Discussion

This propertycontains a snapshot of the path at any given point in time. Getting thisproperty returns an immutable path object that you can pass to Core Graphicsfunctions. The path object itself is owned by theUIBezierPath object and is valid only until you makefurther modifications to the path.

这个属性包含任何给定适合的路径快照。访问此这个属性将获得一个可以传递给Core Graphics方法的不便的路径对象。路径对象本身的拥有者是UIBezierPath对象,并且只有你对路径做进一步修改的时候才会有效。

 

You can set the value of this property to a path you built usingthe functions of the Core Graphics framework. When setting a new path, thismethod makes a copy of the path you provide.

你设置这个属性的值为使用Core Graphics框架函数建立的路径。当设置新的路径时,这个方法会copy一份你提供的值。

Availability

Available iniOS 3.2 and later.iOS3.2及以后可用)

currentPoint Property

 

The current point in the graphics path. (read-only)

图形路径中的当前点

Declaration

OBJECTIVE-C

@property(nonatomicreadonlyCGPoint currentPoint

Discussion

The value in thisproperty represents the starting point for new line and curve segments. If thepath is currently empty, this property contains the value CGPointZero.

这个属性值确定了绘制直线或曲线时的起始点。如果当前点为空,这个属性值为CGPointZero

Availability

Available iniOS 3.2 and later.iOS3.2及以后可用)

See Also

empty

 

Accessing Drawing Properties(绘制属性)


lineWidth Property

The line width of the path.

路径线的宽度

Declaration

OBJECTIVE-C

@property(nonatomicCGFloat lineWidth

Discussion

The line width defines the thickness of the receiver's strokedpath. A width of 0 is interpreted as the thinnest line that can be rendered ona particular device. The actual rendered line width may vary from the specifiedwidth by as much as 2 device pixels, depending on the position of the line withrespect to the pixel grid and the current anti-aliasing settings. The width ofthe line may also be affected by scaling factors specified in the currenttransformation matrix of the active graphics context.

lineWidth属性定义了接收者描边路径的厚度。0宽度是可以在特殊设备上绘制的最薄线。实际呈现的线条宽度也许会从指定的宽度到多达2设备像素宽,取决于线条相对于像素网格和当前的抗锯齿设置。线条的宽度也被会当前活动的缩放变化矩阵影响。

The default line width is 1.0.

默认的线条宽度值为1.0

Availability

Available iniOS 3.2 and later.iOS3.2及以后可用)

 


lineCapStyle Property

 

The shape of the paths end points when stroked.

指定线的末端如何绘制(类似于HTML DOM lineCap,http://www.w3school.com.cn/jsref/prop_canvasrenderingcontext2d_linecap.asp

Declaration

OBJECTIVE-C

@property(nonatomicCGLineCap lineCapStyle

Discussion

The line capstyle is applied to the start and end points of any open subpaths. Thisproperty does not affect closed subpaths. The default line cap style is kCGLineCapButt.

线帽的样式将应用于任何开放路径的起始点和终点。这个属性不会影响封闭路径的线帽形式。默认样式为kCGLintCapButtCGPath中的属性)

enum CGLineCap { kCGLineCapButt,kCGLineCapRound,kCGLineCapSquare };

https://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CGPath/index.html#//apple_ref/c/econst/kCGLineCapButt

Availability

Available iniOS 3.2 and later.iOS3.2及以后可用)

 


lineJoinStyle Property

 

The shape of the joints between connected segments of a strokedpath.

指定线段连接点处的形状

Declaration

OBJECTIVE-C

@property(nonatomicCGLineJoin lineJoinStyle

Discussion

The defaultline join style is kCGLineJoinMiter.

默认的连接点风格为kCGLineJoinMiter

enum CGLineJoin { kCGLineJoinMiter,kCGLineJoinRound,kCGLineJoinBevel };typedefenumCGLineJoin CGLineJoin;

https://developer.apple.com/library/ios/documentation/GraphicsImaging/Reference/CGPath/index.html#//apple_ref/c/econst/kCGLineJoinMiter

Availability

Available iniOS 3.2 and later.

miterLimit Property

The limiting value that helps avoid spikes at junctions betweenconnected line segments.

限制值避免了线段连接点之间的尖角

Declaration

OBJECTIVE-C

@property(nonatomicCGFloat miterLimit

Discussion

The miter limithelps you avoid spikes in paths that use the kCGLineJoinMiter join style. If the ratio of the miterlength—that is, the diagonal length of the miter join—to the line thicknessexceeds the miter limit, the joint is converted to a bevel join. The defaultmiter limit is 10, which results in the conversion of miters whose angle at thejoint is less than 11 degrees.

斜接限制值避免了使用kCGLineJoinMiter连接风格的路径尖角。如果线宽斜切长度()的比率超过了这个值,那么斜接连接将转换成斜角连接。斜接限制值的默认值是10,这个结果将使得任何在此连接点上的斜切转换率少于11度。(简单来说就是控制连接线的尖角程度,http://tieba.baidu.com/p/1282157296


Availability

Available iniOS 3.2 and later.

 


flatness Property

The factor that determines the rendering accuracy for curvedpath segments.

这个值决定了曲线路径线段绘制的精确度

Declaration

OBJECTIVE-C

@property(nonatomicCGFloat flatness

Discussion

The flatnessvalue measures the largest permissible distance (measured in pixels) between apoint on the true curve and a point on the rendered curve. Smaller valuesresult in smoother curves but require more computation time. Larger valuesresult in more jagged curves but are rendered much faster. The default flatnessvalue is 0.6.

平整度值规定了真实曲线上的点和绘制出来的曲线的点之间的最远距离。平整度越小,绘制的曲线越平滑但是时绘制的时间也越长。平整度越打,绘制的曲线越粗糙,但是绘制的速度也越快。默认平整度值为0.6

 

In most cases, you should not change the flatness value.However, you might increase the flatness value temporarily to minimize theamount of time it takes to draw a shape temporarily (such as during scrolling).

大多数情况下,你不需要改变平整度的值。然而,你也许希望提高平整度减少绘制所花费的时间(例如滚动的时候)。

Availability

Available iniOS 3.2 and later.iOS3.2及以后可用)

 

 

 

usesEvenOddFillRule Property

A Boolean indicating whether the even-odd winding rule is in usefor drawing paths.

Boolean值,决定绘制路径是否使用奇偶缠绕规则(http://www.cnblogs.com/yaozhongxiao/archive/2012/04/28/2474779.html

Declaration

OBJECTIVE-C

@property(nonatomicBOOL usesEvenOddFillRule

Discussion

If YES, the path is filled using the even-odd rule. If NO, it is filled using the non-zero rule. Both rules arealgorithms to determine which areas of a path to fill with the current fillcolor. A ray is drawn from a point inside a given region to a point anywhereoutside the path’s bounds. The total number of crossed path lines (includingimplicit path lines) and the direction of each path line are then interpretedas follows:

如果为YES,路径填充使用奇偶缠绕规则。如果值为NO,填充规则使用非零缠绕。两种规则都是用来确定区域是否需要填充颜色。以给定区域中的一点为起点,绘制一条从该点向路径边缘外延伸的射线。该射线与路径相交的次数和路径的方向将做如下解释:

·       For the even-odd rule, if the total number ofpath crossings is odd, the point is considered to be inside the path and thecorresponding region is filled. If the number of crossings is even, the pointis considered to be outside the path and the region is not filled.

对于奇偶缠绕规则来说,使用该线条与路径相交的次数。如果计数为奇数,则填充相关区域。如果计数为偶数,则不填充相关区域。

·       For the non-zero rule, the crossing of aleft-to-right path counts as +1 and the crossing of a right-to-left path countsas -1. If the sum of the crossings is nonzero, the point is considered to beinside the path and the corresponding region is filled. If the sum is 0, thepoint is outside the path and the region is not filled.

http://www.cnblogs.com/yaozhongxiao/archive/2012/04/28/2474779.html

http://blog.sina.com.cn/s/blog_6084f5880100u4q4.html

对于非零缠绕,正向缠绕路径将得到赋值+1,负向缠绕路径将得到赋值-1

如果路径的组合值不为0,则填充相交区域。如果组合值为0,则不填充相交区域。


The defaultvalue of this property is NO. For more information about winding rules andhow they are applied to subpaths, see Quartz 2D Programming Guide.

 

默认值为NO。关于缠绕规则以及它们如何应用到子路径上,参考Quartz 2D Programming Guide(https://developer.apple.com/library/ios/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/Introduction/Introduction.html#//apple_ref/doc/uid/TP30001066)

Availability

Available iniOS 3.2 and later.iOS3.2及以后可用)

 


- setLineDash:count:phase:

Sets the line-stroking pattern for the path.

设置路径的绘制样式

Declaration

OBJECTIVE-C

- (void)setLineDash:(const CGFloat *)pattern
              count:(NSInteger)count
              phase:(CGFloat)phase

Parameters

pattern

A C-style array of floating point values that contains the lengths (measured in points) of the line segments and gaps in the pattern. The values in the array alternate, starting with the first line segment length, followed by the first gap length, followed by the second line segment length, and so on.

C语言风格的浮点值数组,确定路径的线段长度和线段之间的长度。路径交替的绘制指定长度的线段和指定长度的间隙。

count

The number of values in pattern.

pattern数组的长度

phase

The offset at which to start drawing the pattern, measured in points along the dashed-line pattern. For example, a phase value of 6 for the pattern 5-2-3-2 would cause drawing to begin in the middle of the first gap.

一开始绘制时跳过的点数。例如pattern的模式为5-2-3-2(绘制5个点、跳过两个点,绘制3个点,跳过2个点,然后重复上述步骤),phrase=6时则跳过6个点,跳过1个点,绘制3个点,跳过两个点;绘制5个点

http://wenku.baidu.com/link?url=V4DVp9BxRYpP6XPCtFaWDd40NBsyzlGwSa

MkmTcO5BANoHBo7me-cZ6L40A_f_ldTT_Mzj02wn4UzpJ_7qPQuJbOCOfNfye

deZp1rkEPHz3

Availability

Available iniOS 3.2 and later.iOS3.2及以后可用)

 


- getLineDash:count:phase:

Retrieves the line-stroking pattern for the path.

取回路径的绘制样式

Declaration

OBJECTIVE-C

- (void)getLineDash:(CGFloat *)pattern
              count:(NSInteger *)count
              phase:(CGFloat *)phase

Parameters

pattern

On input, a C-style array of floating point values, or nil if you do not want the pattern values. On output, this array contains the lengths (measured in points) of the line segments and gaps in the pattern. The values in the array alternate, starting with the first line segment length, followed by the first gap length, followed by the second line segment length, and so on.

设置值的时候是C语言风格的数组,或者是nil。输出为线段和间隙的长度值(以点来计算)。这个数组中的值交替出现。

count

On input, a pointer to an integer or nil if you do not want the number of pattern entries. On output, the number of entries written to pattern.

输入的时候,是一个整数值或者nil。输出的时候是pattern的数组长度。

phase

On input, a pointer to a floating point value or nil if you do not want the phase. On output, this value contains the offset at which to start drawing the pattern, measured in points along the dashed-line pattern. For example, a phase of 6 in the pattern 5-2-3-2 would cause drawing to begin in the middle of the first gap.

输入的时候,是一个浮点值或者nil。输入的时候表示的是绘制一开始绘制路径时跳过的位置。例如pattern的模式为5-2-3-2(绘制5个点、跳过两个点,绘制3个点,跳过2个点,然后重复上述步骤),phrase=6时则跳过6个点,跳过1个点,绘制3个点,跳过两个点;绘制5个点

Discussion

The array inthe pattern parameter must be large enough to hold all of the returnedvalues in the pattern. If you are not sure how many values there might be, youcan call this method twice. The first time you call it, do not pass a value for pattern but use the returned value in the count parameter to allocate an array of floating-point numbers thatyou can then pass in the second time.

样式参数pattern必须足够长以承载返回值。假如你不确定pattern数组的长度,你可以调用此函数两次。第一次,不要传给pattern赋值,使用count参数返回的值作为数组的长度,从而在第二次调用此函数的时候可以获得数组的内容。

Availability

Available iniOS 3.2 and later.iOS3.2及以后可用)

 

Drawing Paths(绘制路径)


- fill

Paints the region enclosed by the receiver’s path using the currentdrawing properties.

使用当前的绘制属性填充接收者路径围成的区域。

Declaration

OBJECTIVE-C

- (void)fill

Discussion

This method fills the path using the current fill color anddrawing properties. If the path contains any open subpaths, this methodimplicitly closes them before painting the fill region.

此方法使用当前的填充色和绘制属性填充路径。如果路径包含开放的子路径,这个方法在填充区域之前会隐式的封闭子路径。

The painted region includes the pixels right up to, but notincluding, the path line itself. For paths with large line widths, this canresult in overlap between the fill region and the stroked path (which is itselfcentered on the path line).

被填充的区域接近但不包括路径线本身。如果路径线比较宽,将导致填充区域和描边的重叠(描边区域中心线为路径线)。

This method automatically saves the current graphics state priorto drawing and restores that state when it is done, so you do not have to savethe graphics state yourself.

这个方法将自动保存之前绘制图像时的上下文环境,当完成绘制的时候后更新环境状态,所以你不需要自己保存绘制环境上下文。

Availability

Available iniOS 3.2 and later.iOS3.2及以后可用)


- fillWithBlendMode:alpha:

 

Paints the region enclosed by the receiver’s path using the specifiedblend mode and transparency values.

使用指定的混合模式和透明值绘制封闭区域

Declaration

OBJECTIVE-C

- (void)fillWithBlendMode:(CGBlendMode)blendMode
                    alpha:(CGFloat)alpha

Parameters

blendMode

The blend mode determines how the filled path is composited with any existing rendered content.

枚举类型。规定已存在的内容如何进行混合。

http://www.cnblogs.com/jacku/articles/2287712.html

alpha

The amount of transparency to apply to the filled path. Values can range between 0.0(transparent) and 1.0 (opaque). Values outside this range are clamped to 0.0 or 1.0.

填充区域的透明度。取值范围为0.0(透明)到1.0(不透明)。超过范围的值被截取成0.01.0

Discussion

This method fills the path using the current fill color anddrawing properties (plus the specified blend mode and transparency value). Ifthe path contains any open subpaths, this method implicitly closes them beforepainting the fill region.

此方法使用当前的填充颜色和绘制属性对路径进行填充(增加了指定的混合模式和透明值)。对区域进行填充前,此方法会隐式的闭合路径中开放的子路径。

The painted region includes the pixels right up to, but notincluding, the path line itself. For paths with large line widths, this canresult in overlap between the fill region and the stroked path (which is itselfcentered on the path line).

填充区域接近但不包含路径线本身。如果路径线比较宽,可能会造成填充区域和路径线的重叠(描边区域中心线为路径线)。

This method automatically saves the current graphics state priorto drawing and restores that state when it is done, so you do not have to savethe graphics state yourself.

此方法自动保存之前绘制的图形上下文状态,并且当绘制完成后更新此状态,所以你不需要手动保存图形上下文状态。

Availability

Available iniOS 3.2 and later.iOS3.2及以后可用)

 


- stroke

Draws a line along the receiver’s path using the current drawingproperties.

使用当前的绘制属性对路径线进行描边。

Declaration

OBJECTIVE-C

- (void)stroke

Discussion

The drawn line is centered on the path with its sides parallelto the path segment. This method applies the current drawing properties to therendered path.

绘制出来的描边居中于路径,并且描边两边平行于路径线段。此方法使用当前的绘制属性对路径进行描边。

This method automatically saves the current graphics state priorto drawing and restores that state when it is done, so you do not have to savethe graphics state yourself.

此方法自动保存之前绘制的图形上下文状态,并且当绘制完成后更新此状态,所以你不需要手动保存图形上下文状态。

Availability

Available iniOS 3.2 and later.iOS3.2及以后可用)


- strokeWithBlendMode:alpha:

Draws a line along the receiver’s path using the specified blendmode and transparency values.

使用指定的混合模式和透明值沿路径进行描边。

Declaration

OBJECTIVE-C

- (void)strokeWithBlendMode:(CGBlendMode)blendMode
                      alpha:(CGFloat)alpha

Parameters

blendMode

The blend mode determines how the stroked path is composited with any existing rendered content.

混合模式决定了描边路径如何和现有的内容进行混合。

alpha

The amount of transparency to apply to the stroked path. Values can range between 0.0(transparent) and 1.0 (opaque). Values outside this range are clamped to 0.0 or 1.0.

描边路径的透明度。取值范围为0.0(透明)到1.0(不透明)。超过此范围的值会被截取为0.01.0

Discussion

The drawn line is centered on the path with its sides parallelto the path segment. This method applies the current stroke color and drawingproperties (plus the specified blend mode and transparency value) to therendered path.

绘制的线段居中于路径线并且其两端平行于路径线段。这使用当前的描边颜色和绘制属性(包括混合模式和透明值)绘制路径。

This method automatically saves the current graphics state priorto drawing and restores that state when it is done, so you do not have to savethe graphics state yourself.

此方法自动保存之前绘制的图形上下文状态,并且当绘制完成后更新此状态,所以你不需要手动保存图形上下文状态。

Availability

Available iniOS 3.2 and later.iOS3.2及以后可用)

 

- addClip

Intersects the area enclosed by the receiver’s path with theclipping path of the current graphics context and makes the resulting shape thecurrent clipping path.

用当前上下文中的裁剪路径裁剪当前区域,使得最终的图形符合当前的裁剪路径。

Declaration

OBJECTIVE-C

- (void)addClip

Discussion

This method modifies the visible drawing area of the currentgraphics context. After calling it, subsequent drawing operations result inrendered content only if they occur within the fill area of the specified path.

使用当前图形上下文修饰绘图区域。调用此函数后,随后,只有处于裁剪区域中的的绘图操作才会起作用。

IMPORTANT

If you need toremove the clipping region to perform subsequent drawing operations, you mustsave the current graphics state (using the CGContextSaveGState function) before calling this method. When youno longer need the clipping region, you can then restore the previous drawingproperties and clipping region using the CGContextRestoreGState function.

如果你需要在随后的绘图操作中移除裁剪区域,那么你需要在调用此函数之前保存图形上下文(使用CGContextSaveGState函数)。当你不在需要裁剪区域的时候,你可以使用CGContextRestoreGState方法恢复当前上下文至之前的绘图属性和裁剪区域。

The usesEvenOddFillRule property is used to determine whether theeven-odd or non-zero rule is used to determine the area enclosed by the path.

usesEvenOddFillRule属性用来确定绘制路径围成的封闭区域时使用奇偶缠绕规则还是零值缠绕规则。

Availability

Available iniOS 3.2 and later.iOS3.2及以后可用)

Hit Detection点击检测


- containsPoint:

Returns a Boolean value indicating whether the area enclosed bythe receiver contains the specified point.

返回一个Boolean值,表明所给点是否包含在封闭区域中。

Declaration

OBJECTIVE-C

- (BOOL)containsPoint:(CGPoint)point

Parameters

point

The point to test against the path, specified in the path object's coordinate system.

要验证的点,指定于路径对象中坐标系统。

Return Value

YES if the point is considered to be within the path’s enclosed areaor NO if it is not.

如果点位于封闭路径区域中返回YES,如果不在则返回NO

Discussion

The receivercontains the specified point if that point is in a portion of a closed subpath thatwould normally be painted during a fill operation. This method uses the valueof the usesEvenOddFillRule property to determine which parts of thesubpath would be filled.

如果指定的点位于封闭子路径的一部分中,则这个路径包含这个点。这个点会在填充操作中被绘制。这个方法使用使用usesEvenOddFillRule属性来确定子路径中的哪一部分被填充。

A point is notconsidered to be enclosed by the path if it is inside an open subpath,regardless of whether that area would be painted during a fill operation.Therefore, to determine mouse hits on open paths, you must create a copy of thepath object and explicitly close any subpaths (using the closePath method) before calling this method.

如果点位于开放的子路径中,那么不论这个点是否会在填充操作中被绘制,都不会被认为是存在于封闭路径之中。既然如此,那么在你调用此方法之前你需要拷贝路径对象并封闭路径中任何开放得子路径(使用closePath方法)才能确定鼠标是否点击在了开放路径中。

Availability

Available in iOS3.2 and later.iOS3.2及以后可用)

 


empty Property

A Boolean value indicating whether the path has any validelements. (read-only)

Boolean值,表明路径是否含有有效值

Declaration

OBJECTIVE-C

@property(readonlygetter=isEmptyBOOL empty

Discussion

Valid pathelements include commands to move to a specified point, draw a line or curvesegment, or close the path. Thus, a path is not considered empty even if allyou do is call the moveToPoint: method.

有效地路径元素包括移动到指定点,绘制直线和曲线段、或者关闭路径。如此,即使你只是调用了moveToPoint:方法,路径也会被认为是有效的。

Availability

Available iniOS 3.2 and later.iOS3.2及以后可用)

 


bounds Property

The bounding rectangle of the path. (read-only)

路径的边框。

Declaration

OBJECTIVE-C

@property(nonatomicreadonlyCGRect bounds

Discussion

The value in this property represents the smallest rectanglethat completely encloses all points in the path, including any control pointsfor Bézier and quadratic curves.

这个属性值表示了一个可以覆盖所有路径点得最小矩形框,包括Bézier的控制点和二次曲线。

Availability

Available iniOS 3.2 and later.iOS3.2及以后可用)

 

 

Applying Transformations(应用变换)

 
- applyTransform:

Transforms all points in the path using the specified affinetransform matrix.

使用指定的仿射变换矩阵对路径进行变换。

Declaration

OBJECTIVE-C

- (void)applyTransform:(CGAffineTransform)transform

Parameters

transform

The transform matrix to apply to the path.

应用于路径上的变换矩阵。

Discussion

This method applies the specified transform to the path’s pointsimmediately. The modifications made to the path object are permanent. If you donot want to permanently modify a path object, you should consider applying thetransform to a copy.

此方法将变换立即应用到路径的点上。对路径对象的修改是永久性的。如果你不想永久的修改一个路径对象,你应考虑将变换应用到拷贝路径上。

Availability

Available iniOS 3.2 and later.iOS3.2及以后可用)

 

 

Constants(常量)

 UIRectCorner

The corners of a rectangle.(矩形的四个角)

Declaration

OBJECTIVE-C

enum {

UIRectCornerTopLeft = 1 << 0,

UIRectCornerTopRight = 1 << 1,

UIRectCornerBottomLeft =1<<2,

UIRectCornerBottomRight =1<<3,

UIRectCornerAllCorners =~0

}; typedef NSUIntegerUIRectCorner;

Constants

·      UIRectCornerTopLeft

The top-left corner of the rectangle.(矩形的左上角)

Available in iOS 3.2 andlater. iOS3.2及以后可用)

·      UIRectCornerTopRight

The top-right corner of the rectangle.(矩形的右上角)

Available in iOS 3.2 andlater. iOS3.2及以后可用)

·      UIRectCornerBottomLeft

The bottom-left corner of the rectangle.(矩形的左下角)

Available in iOS 3.2 andlater. iOS3.2及以后可用)

·      UIRectCornerBottomRight

The bottom-right corner of the rectangle.(矩形的右下角)

Available in iOS 3.2 andlater. iOS3.2及以后可用)

·      UIRectCornerAllCorners

All corners of the rectangle.(矩形的四个角)

Available in iOS 3.2 andlater.iOS3.2及以后可用)

Discussion

The specified constants reflect the corners of a rectangle thathas not been modified by an affine transform and is drawn in the defaultcoordinate system (where the origin is in the upper-left corner and positivevalues extend down and to the right).

这些特殊的常量值反应了矩形中未被放射变化修改的角,这些角被绘制于默认坐标系统中(原点在左上角,向下和向右为正值)。

Import Statement

OBJECTIVE-C

@import UIKit;

Availability

Available iniOS 3.2 and later.iOS3.2及以后可用)

0 0
原创粉丝点击