UIBezierPath Class Reference翻译

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值