UIBezierPath類

UIBezierPath Class Reference

譯:UIBezierPath類
封裝了Core Graphics(純C語言框架)的Objective—C類,不能實現(xiàn)陰影和漸變效果,要實現(xiàn)的話還得用純C的Core Graphics框架。
翻譯于2016年9月28日,第一版內(nèi)容未校驗


注解:貝塞爾曲線(Bézier curve),又稱貝茲曲線或貝濟(jì)埃曲線,是應(yīng)用于二維圖形應(yīng)用程序的數(shù)學(xué)曲線。一般的矢量圖形軟件通過它來精確畫出曲線,貝茲曲線由線段與節(jié)點組成,節(jié)點是可拖動的支點,線段像可伸縮的皮筋,我們在繪圖工具上看到的鋼筆工具就是來做這種矢量曲線的。貝塞爾曲線是計算機(jī)圖形學(xué)中相當(dāng)重要的參數(shù)曲線,貝塞爾曲線于1962,由法國工程師皮埃爾·貝塞爾(Pierre Bézier)所廣泛發(fā)表,他運用貝塞爾曲線來為汽車的主體進(jìn)行設(shè)計。貝塞爾曲線最初由Paul de Casteljau于1959年運用de Casteljau演算法開發(fā),以穩(wěn)定數(shù)值的方法求出貝茲曲線。
貝塞爾曲線就是這樣的一條曲線,它是依據(jù)四個位置任意的點坐標(biāo)繪制出的一條光滑曲線。在歷史上,研究貝塞爾曲線的人最初是按照已知曲線參數(shù)方程來確定四個點的思路設(shè)計出這種矢量曲線繪制法。貝塞爾曲線的有趣之處更在于它的“皮筋效應(yīng)”,也就是說,隨著點有規(guī)律地移動,曲線將產(chǎn)生皮筋伸引一樣的變換,帶來視覺上的沖擊。1962年,法國數(shù)學(xué)家Pierre Bézier第一個研究了這種矢量繪制曲線的方法,并給出了詳細(xì)的計算公式,因此按照這樣的公式繪制出來的曲線就用他的姓氏來命名是為貝塞爾曲線。

The UIBezierPath class lets you define a path consisting of straight 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. Paths can define simple shapes such as rectangles, ovals, and arcs or they can define complex polygons that incorporate a mixture of straight and curved line segments. After defining the shape, you can use additional methods of this class to render the path in the current drawing context.

譯:UIBezierPath類允許您定義一個由直線和曲線段組成的路徑和在您的自定義視圖上渲染路徑。你使用這個類首先指定你的幾何路徑。路徑可以定義簡單的形狀如矩形、橢圓、弧或可以把直線和曲線段混合成復(fù)合多邊形。定義形狀后,你可以使用這個類的添加方法將路徑添加在當(dāng)前繪圖上下文進(jìn)行渲染。

A UIBezierPath object combines the geometry of a path with attributes that describe the path during rendering. You set the geometry and attributes separately and can change them independent of one another. Once you have the object configured the way you want it, you can tell it to draw itself in the current context. Because the creation, configuration, and rendering process are all distinct steps, Bezierpath 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 options between successive drawing calls.

譯:UIBezierPath對象結(jié)合了幾何路徑及其如何渲染屬性。你分別設(shè)置幾何結(jié)構(gòu)和屬性,可以互相獨立地改變他們。一旦你有了所希望方式配置的對象,你可以告訴它在當(dāng)前上下文中繪畫出本身。因為創(chuàng)建、配置和渲染過程都是不同階段,Bezierpath對象可以簡單地重用你的代碼。您甚至可以使用同一個對象去渲染同一個形狀多次,或許在改變渲染選項和連續(xù)繪畫之間調(diào)用同一個Bezierpath對象。

You set the geometry of a path by manipulating the path’s current point. When you create a new empty path object, the current point is undefined and must be set explicitly. To move the current point without drawing a segment, you use the moveToPoint: method. All other methods result in the addition of either a line or curve segments to the path. The methods for adding new segments always assume you arestarting at the current point and ending at some new point that you specify. After adding the segment,the end point of the new segment automatically becomes the current point.

譯:您通過操作路徑的當(dāng)前點來設(shè)置幾何路徑。當(dāng)您創(chuàng)建一個新的空path對象,當(dāng)前點是未定義的,必須顯式地設(shè)置。您使用moveToPoint:方法來移到當(dāng)前點而不會畫線段。所有其他方法產(chǎn)生不適添加直線就是曲線段到路徑。添加新線段方法總是假設(shè)你在當(dāng)前點和您指定的結(jié)束點。在添加線段之后,新線段的終點自動成為當(dāng)前點。

A single 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 from the current point to the first point in the subpath. Calling the moveToPoint: method ends the current subpath (without closing it) and sets the starting point of the next subpath. The subpaths of a Bezier path object share the same drawing attributes and must be manipulated as a group. To draw subpaths with different attributes, you must put each subpath in its own UIBezierPath object.

譯:一個Bezier曲線路徑對象可以包含任意數(shù)量的開放或封閉的子路徑,其中每個子路徑都是相連的路徑段。調(diào)用closePath方法添加一條從當(dāng)前點到首發(fā)點的直線段關(guān)閉子路徑。調(diào)用moveToPoint:方法結(jié)束當(dāng)前的子路徑(沒有關(guān)閉)和然后設(shè)置下一子路徑起始點。Bezier曲線路徑的子路徑對象共享相同的屬性和必須作為一個整體操作。畫不同的屬性的子路徑,你必須將每一個子路徑放到它自己的UIBezierPath對象中去。

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

譯:配置Bezier曲線路徑的幾何特性和屬性之后,你使用描邊和填充方法將路徑畫在當(dāng)前圖形上下文。stroke方法使用當(dāng)前stroke顏色和Bezier曲線路徑對象的屬性描繪路徑的輪廓。同樣,fill方法使用當(dāng)前的填充顏色填充封閉的路徑。(你使用UIColor類設(shè)置stroke和fill顏色。)

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

譯:除了使用Bezier曲線路徑對象去畫形狀,您還可以使用它來定義一個新的剪裁區(qū)域。addClip方法描寫路徑對象與當(dāng)前圖形上下文裁剪區(qū)域的交叉形狀。在隨后繪畫,實際上只有在新的交叉區(qū)域線的內(nèi)容呈現(xiàn)給圖形上下文。

Creating a UIBezierPath Object

譯:創(chuàng)建一個UIBezierPath對象

+ bezierPath

Creates and returns a new UIBezierPath object.

譯:創(chuàng)建和返回一個UIBezierPath對象

Declaration

譯:聲明

<code>
OBJECTIVE-C
+ (instancetype)bezierPath
</code>

Return Value

A new empty path object. ->一個新的空的path對象

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用


+ bezierPathWithRect:
Creates and returns a new UIBezierPath object initialized with a rectangular path.

譯:創(chuàng)建并返回一個新的初始化為矩形的UIBezierPath對象.

Declaration

譯:聲明

<code>
SWIFT
convenience->便利構(gòu)造方法: init(rect rect: CGRect)
</code>
<code>
OBJECTIVE-C
+ (instancetype)bezierPathWithRect:(CGRect)rect
Parameters
rect |The rectangle describing the path to create.->創(chuàng)建描述矩形的路徑
</code>

Return Value

A new path object with the rectangular path.->一個矩形新路徑對象

Discussion

This method creates a closed subpath by starting at the origin of rect and adding line segments in a clockwise direction (relative to the default coordinate system).->這個方法通過在矩形的原點開始順時針方向添加線段創(chuàng)建一個封閉的子路徑,(相對于默認(rèn)坐標(biāo)系)

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用


+ bezierPathWithOvalInRect:

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

譯:創(chuàng)建并返回一個初始化指定內(nèi)切矩形的橢圓形的新UIBezierPath對像路徑。

Declaration

譯:聲明

<code>
SWIFT
convenience->便利構(gòu)造函數(shù): init(ovalInRect rect: CGRect)
OBJECTIVE-C
+ (instancetype)bezierPathWithOvalInRect:(CGRect)rect
Parameters
rect |The rectangle in which to inscribe an oval.->內(nèi)切橢圓形的矩形
</code>

Return Value

A new path object with the oval path.->一個新的橢圓形路徑

Discussion

This method creates a closed subpath that approximates the oval using a sequence of Bézier curves.The path is created in a clockwise direction (relative to the default coordinate system). If the rect parameter specifies a square, the inscribed path is a circle.->這個方法使用一系列?貝塞爾曲線數(shù)列創(chuàng)建一個近似于橢圓形的封閉子路徑。這是一個順時針方向創(chuàng)建的路徑(相對于默認(rèn)坐標(biāo)系)。如果rect參數(shù)指定了一個方形,內(nèi)切路徑是一個圓。

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用


+ bezierPathWithRoundedRect:cornerRadius:

Creates and returns a new UIBezierPath object initialized with a rounded rectangular path.

譯:創(chuàng)建并返回一個新的初始化一個圓角矩形UIBezierPath對象路徑。

Declaration

譯:聲明

<code>
SWIFT
convenience->便利構(gòu)造函數(shù): init(roundedRect rect: CGRect,
cornerRadius cornerRadius: CGFloat)
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時為一個沒有圓角的矩形。值超過矩形的寬度或高度一半時,強(qiáng)制為寬度或高度的一半。
</code>

Return Value

A new path object with the rounded rectangular path.->一個新帶圓角矩形路徑對象。

Discussion

This method creates a closed subpath, proceeding in a clockwise direction (relative to the default coordinate system) as it creates the necessary line and curve segments.->這個方法沿順時針方向創(chuàng)建一個帶必要的直線和曲線段的封閉子路徑(相對于默認(rèn)坐標(biāo)系統(tǒng))

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用


+ bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:

Creates and returns a new UIBezierPath object initialized with a rounded rectangular path.

譯:創(chuàng)建并返回一個新的初始化為一個圓角矩形UIBezierPath路徑對象。

Declaration

譯:聲明

<code>
SWIFT
convenience->便利構(gòu)造函數(shù): init(roundedRect rect: CGRect,
byRoundingCorners corners: UIRectCorner,
cornerRadii cornerRadii: CGSize)
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.->你想要的圓角的位掩碼值。你可以使用這個參數(shù)去只將矩形一個角進(jìn)行倒角。
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.->每一個角的的橢圓半徑。值大于矩形的寬度或?qū)挾纫话霑r,強(qiáng)制為寬度或高度的一半。
</code>

Return Value

A new path object with the rounded rectangular path.->個新的圓角矩形路徑對象。

Discussion

This method creates a closed subpath, proceeding in a clockwise direction (relative to the default coordinate system) as it creates the necessary line and curve segments.->這個方法沿順時針方向創(chuàng)建一個必要的直線和曲線段的封閉子路徑,(相對于默認(rèn)坐標(biāo)系統(tǒng)),。

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用


+ bezierPathWithArcCenter:radius:startAngle:endAngle:clockwise:

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

譯:創(chuàng)建并返回一個初始化一個圓弧的新UIBezierPath對象。

Declaration

譯:聲明

<code>
SWIFT
convenience->便利構(gòu)造函數(shù): init(arcCenter center: CGPoint,
radius radius: CGFloat,
startAngle startAngle: CGFloat,
endAngle endAngle: CGFloat,
clockwise clockwise: Bool)
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 definethe arc.->指出圓形的中心點(在當(dāng)前坐標(biāo)系)來定義一個圓弧。
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).->指定圓弧結(jié)束的角度(單位為弧度)。
clockwise| The direction in which to draw the arc.->指定圓弧描繪的方向。
</code>

Return Value

A new path object with the specified arc.->一個指定弧度的新路徑對象

Discussion

This method creates an open subpath. The created arc lies on the perimeter of the specified circle.When drawn in the default coordinate system, 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 thesame start and end angles but setting the clockwise parameter set to NO draws the top half of the circle.->這個方法創(chuàng)建一個開放的子路徑。創(chuàng)建的圓弧位于指定圓的周長。當(dāng)在默認(rèn)坐標(biāo)系統(tǒng),開始和結(jié)束的角度是基于如圖1所示的坐標(biāo)系。例如,指定一個開始角弧度為0,結(jié)束角弧度為π的圓弧,和設(shè)置clockwise參數(shù)為YES畫的是圓的下半部。然而設(shè)定clockwise為NO,畫的是圓的下半部。

Figure 1 Angles in the default coordinate system

譯:圖1 在默認(rèn)坐標(biāo)系的角度

Snip20160927_1.png

After calling this method, the current point is set to the point on the arc at the end angle of the circle.->調(diào)用這個方法,當(dāng)前點設(shè)為圓弧圓周上終點。

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用


+ bezierPathWithCGPath:

Creates and returns a new UIBezierPath object initialized with the contents of a Core Graphics path.->創(chuàng)建并返回一個初始化為核心圖形內(nèi)容的新UIBezierPath對象路徑。

Declaration

譯:聲明

<code>
SWIFT
convenience->便利構(gòu)造函數(shù): init(CGPath CGPath: CGPath)
OBJECTIVE-C
+ (instancetype)bezierPathWithCGPath:(CGPathRef)CGPath
Parameters
CGPath | The Core Graphics path from which to obtain the initial path information. If this parameteris nil, the method raises an exception.->核心圖形的路徑獲得最初的路徑信息。如果這參數(shù)為nil,該方法提出了一個異常。
</code>

Return Value

A new path object with the specified path information.->包含指定路徑信息的新路徑對象。

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用


- bezierPathByReversingPath

Creates and returns a new bezier path object with the reversed contents of the current path.->創(chuàng)建并返回一個逆轉(zhuǎn)當(dāng)前路徑內(nèi)容的新的bezier曲線路徑對象。

Declaration

譯:聲明

<code>
SWIFT
func bezierPathByReversingPath() -> UIBezierPath
OBJECTIVE-C
- (UIBezierPath *)bezierPathByReversingPath
</code>

Return Value

A new path object with the same path shape but for which the path has been created in the reverse direction.->創(chuàng)建一個具有相同路徑但路徑方向相反新的路徑對象.

Discussion

Reversing a path does not necessarily change the appearance of the path when rendered. Instead, it changes the direction in which path segments are drawn. For example, reversing the path of a rectangle(whose line segments are normally drawn starting at the origin and proceeding in a counter clockwise direction) causes its line segments to be drawn in a clockwise direction instead. Drawing a reversed path could affect the appearance of a filled pattern, depending on the pattern and the fill rule in use.->扭轉(zhuǎn)了路徑渲染不一定改變路徑的外觀。相反,它改變了路徑片段繪畫方向。例如,扭轉(zhuǎn)一個矩形的路徑(其線段通常從原點開始反時針繪畫)導(dǎo)致其線段沿順時針方向繪畫。根據(jù)渲染模式和fill規(guī)則,畫一個相反路徑會影響fill模式的外觀。
This method reverses each whole or partial subpath in the path object individually.->該方法分別改變路徑中的每個或全部子路徑對象

Availability

Available in iOS 6.0 and later.->iOS 6.0以后適用

Constructing a Path

譯:構(gòu)造路徑

- moveToPoint:
Moves the receiver’s current point to the specified location.->移動當(dāng)前點到指定的位置

Declaration

譯:聲明

<code>
SWIFT
func moveToPoint(_ point: CGPoint)
OBJECTIVE-C
- (void)moveToPoint:(CGPoint)point
Parameters
point | A point in the current coordinate system.->在當(dāng)前坐標(biāo)系的一個點
</code>

Discussion

This method implicitly ends the current subpath (if any) and sets the current point to the value in the point parameter. When ending the previous subpath, this method does not actually close the subpath.Therefore, the first and last points of the previous subpath are not connected to each other.->這種方法隱式結(jié)束當(dāng)前的子路徑(如果有的話),并設(shè)置當(dāng)前點指向參數(shù)中的點。結(jié)束上一個子路徑時,這種方法實際上并不關(guān)閉子路徑。因此,之前子路徑的第一個和最后一個點不是彼此連接的。
For many path operations, you must call this method before issuing any commands that cause a line orcurve segment to be drawn.->對于許多路徑操作,您要去畫一條線段前,必須調(diào)用這個方法。

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用


- addLineToPoint:

Appends a straight line to the receiver’s path.->添加一條直線到路徑

Declaration

譯:聲明

<code>
SWIFT
func addLineToPoint(_ point: CGPoint)
OBJECTIVE-C
- (void)addLineToPoint:(CGPoint)point
Parameters
point | The destination point of the line segment, specified in the current coordinate system.->在當(dāng)前的坐標(biāo)系統(tǒng),指定一條的目標(biāo)點的線段。
</code>

Discussion

This method creates a straight line segment starting at the current point and ending at the point specified by the point parameter. After adding the line segment, this method updates the current point to the value in point.->這個方法創(chuàng)建了一條從當(dāng)前開始點到這參數(shù)指定的終點的一條直線。添加線段后,這種方法更新當(dāng)前點為參數(shù)指定的點。
You must set the path’s current point (using the moveToPoint: method or through the previous creation of a line or curve segment) before you call this method. If the path is empty, this method does nothing.->必須設(shè)置路徑的當(dāng)前點(使用moveToPoint:方法或通過前面直線或曲線段的創(chuàng)建)在你調(diào)用這個方法。如果路徑是空的,這個方法并沒有做什么。

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用


- addArcWithCenter:radius:startAngle:endAngle:clockwise:

Appends an arc to the receiver’s path.->添加一條圓弧到路徑

Declaration

譯:聲明

<code>
SWIFT
func addArcWithCenter(_ center: CGPoint,radius
radius: CGFloat,
startAngle startAngle: CGFloat,
endAngle endAngle: CGFloat,
clockwise clockwise: Bool)
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.->指定圓的中心點(在當(dāng)前坐標(biāo)系統(tǒng))用于定義圓弧。
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.->圓弧繪畫方向。
</code>

Discussion

This method adds the specified arc beginning at the current point. The created arc lies on the perimeter of the specified circle. When drawn in the default coordinate system, the start and end angles are basedon 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 tophalf of the circle.->這種方法在當(dāng)前點開始增加指定的圓弧,創(chuàng)建的弧位位于指定圓形的周長。當(dāng)在默認(rèn)的坐標(biāo)系統(tǒng),開始和結(jié)束的角度是圖1所示的基本圓形。例如,指定一個開始角度0弧度,結(jié)束角度為π弧度,設(shè)置順時針參數(shù)為YES,將畫圓的下半部分。然而,指定相同的開始和結(jié)束角度,但設(shè)置順時針參數(shù)設(shè)置為NO,將畫圓形的下半部。
After calling this method, the current point is set to the point on the arc at the end angle of the circle.->調(diào)用這個方法后,當(dāng)前點為圓弧周長的終點上。

Availability

Available in iOS 4.0 and later.->iOS 4.0以后適用


- addCurveToPoint:controlPoint1:controlPoint2:

Appends a cubic Bézier curve to the receiver’s path.->添加一條cubic貝塞爾曲線到路徑

Declaration

譯:聲明

<code>
SWIFT
func addCurveToPoint(_ endPoint: CGPoint,
controlPoint1 controlPoint1: CGPoint,
controlPoint2 controlPoint2: CGPoint)
OBJECTIVE-C
- (void)addCurveToPoint:(CGPoint)endPoint
controlPoint1:(CGPoint)controlPoint1
controlPoint2:(CGPoint)controlPoint2
Parameters
endPoint | The end point of the curve.->曲線終點
controlPoint1 | 用來計算曲線的第一個控制點
controlPoint2 | 用來計算曲線的第二個控制點
</code>

Discussion

This method appends a cubic Bézier curve from the current point to the end point specified by the endPoint parameter. The two control points define the curvature of the segment. Figure 2 shows an approximation of a cubic Bézier curve given a set of initial points. The exact curvature of the segment involves a complex mathematical relationship between all of the points and is well documented online.->這個方法添加一條從當(dāng)前點到通過參數(shù)指定終點的cubic貝塞爾曲線。這兩個控制點定義線段的曲率。圖2顯示了給定一組初始點計算出接近于cubic貝塞爾曲線。精確曲率的曲線需要所有點復(fù)雜的數(shù)學(xué)運算。

Figure 2 A cubic Bézier curve

譯:一條cubic貝塞爾曲線

Snip20160927_2.png

You must set the path’s current point (using the moveToPoint: method or through the previous creationof a line or curve segment) before you call this method. If the path is empty, this method does nothing.After adding the curve segment, this method updates the current point to the value in point.->在你調(diào)用這個方法之前必須設(shè)置路徑的當(dāng)前點(使用moveToPoint:方法或通過前面創(chuàng)建直線或曲線段方法)。如果路徑是空的,這個方法并沒有做些什么。添加曲線段之后,這方法更新當(dāng)前指向參數(shù)指定的終點。

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用


- addQuadCurveToPoint:controlPoint:

Appends a quadratic Bézier curve to the receiver’s path.->添加一條2次方貝塞爾曲線到路徑

Declaration

譯:聲明

<code>
SWIFT
func addQuadCurveToPoint(_ endPoint: CGPoint,
controlPoint controlPoint: CGPoint)
OBJECTIVE-C
- (void)addQuadCurveToPoint:(CGPoint)endPoint
controlPoint:(CGPoint)controlPoint
Parameters
endPoint | The end point of the curve.->曲線終點
controlPoint | The control point of the curve.->曲線控制點
</code>

Discussion

This method appends a quadratic Bézier curve from the current point to the end point specified by the endPoint parameter. The relationships between the current point, control point, and end point are what defines the actual curve. Figure 3 shows some examples of quadratic curves and the approximate curve shape based on some sample points. The exact curvature of the segment involves a complex mathematical relationship between the points and is well documented online.->這種方法從當(dāng)前點到參數(shù)指定終點添加一條二次方貝塞爾曲線。當(dāng)前點,曲率控制點,終點三個點之間的關(guān)系如圖3顯示了一些基于樣本點計算出二次方曲線示例。精確曲率涉及到這些點之間復(fù)雜的數(shù)學(xué)計算。
Figure 3 Quadratic curve examples

譯:2次方曲線樣本

Snip20160927_3.png

You must set the path’s current point (using the moveToPoint: method or through the previous creationof a line or curve segment) before you call this method. If the path is empty, this method does nothing.After adding the curve segment, this method updates the current point to the value in point.->在你調(diào)用這個方法之前必須設(shè)置路徑的當(dāng)前點(使用moveToPoint:方法或通過前面創(chuàng)建直線或曲線段方法)。如果路徑是空的,這個方法并沒有做些什么。添加曲線段之后,這方法更新當(dāng)前指向參數(shù)指定的終點。

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用


- closePath
Closes the most recently added subpath.->關(guān)閉當(dāng)前添加的子路徑

Declaration

譯:聲明

<code>
SWIFT
func closePath()
OBJECTIVE-C
- (void)closePath
</code>

Discussion

This method closes the current subpath by creating a line segment between the first and last points inthe subpath. This method subsequently updates the current point to the end of the newly created line segment, which is also the first point in the now closed subpath.->這個方法創(chuàng)建一條從起始點到子路徑終點的線段關(guān)閉當(dāng)前子路徑。這個方法從當(dāng)前點創(chuàng)建一條線段到終點(也是起始點)關(guān)閉子路徑。

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用


- removeAllPoints

Removes all points from the receiver, effectively deleting all subpaths.->從接受者刪除所有點,有效地刪除所有子路徑。

Declaration

譯:聲明

<code>
SWIFT
func removeAllPoints()
OBJECTIVE-C
-(void)removeAllPoints
</code>

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用


- appendPath:

Appends the contents of the specified path object to the receiver’s path.->添加一條指定內(nèi)容的路徑到路徑對象中

Declaration

譯:聲明

<code>
SWIFT
func appendPath(_ bezierPath: UIBezierPath)
OBJECTIVE-C
- (void)appendPath:(UIBezierPath *)bezierPath
Parameters
bezierPath |The path to add to the receiver 添加路徑到接受者
</code>

Discussion

This method adds the commands used to create the path in bezierPath to the end of the receiver’s path.This method does not explicitly try to connect the subpaths in the two objects, although the operations in bezierPath might still cause that effect.->這種方法創(chuàng)建bezierPath路徑添加到用于接收者的結(jié)束路徑。這種方法不明確嘗試連接在兩個物體的子路徑,盡管操作bezierPath路徑仍然會導(dǎo)致那樣的結(jié)果。

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用


CGPath (Property/屬性)
The Core Graphics representation of the path.

譯:表示Core Graphics路徑

Declaration

譯:聲明

<code>
SWIFT
var CGPath: CGPath
OBJECTIVE-C
@property(nonatomic) CGPathRef CGPath
</code>

Discussion

This property contains a snapshot of the path at any given point in time. Getting this property returns an immutable path object that you can pass to Core Graphics functions. The path object itself is owned by the UIBezierPath object and is valid only until you make further modifications to the path.->這個屬性包含一個在任何給定的時間點上路徑快照的。讓這個屬性返回不可變的路徑對象,您可以通過Core Graphics函數(shù)使用。路徑對象本身擁有UIBezierPath對象和直到您進(jìn)一步修改路徑有效。

You can set the value of this property to a path you built using the functions of the Core Graphics framework. When setting a new path, this method makes a copy of the path you provide.->你可以設(shè)置這個路徑的屬性值給你使用的Core Graphics框架函數(shù)使用。當(dāng)設(shè)置一個新的路徑,這種方法使用您提供的路徑的副本。

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用

currentPoint (Property/屬性)

The current point in the graphics path. (read-only)->圖形路徑當(dāng)前點。(只讀)

Declaration

譯:聲明

<code>
SWIFT
var currentPoint: CGPoint { get }
OBJECTIVE-C
@property(nonatomic, readonly) CGPoint currentPoint
</code>

Discussion

The value in this property represents the starting point for new line and curve segments. If the path is currently empty, this property contains the value CGPointZero.->在這個屬性的值代表了新的線段和曲線段的起點。如果路徑當(dāng)前為空,這個屬性包含CGPointZero值。

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用
See Also
empty ->無

</br>

Accessing Drawing Properties

</br>
lineWidth (Property/屬性)

The line width of the path.->路徑線寬

Declaration

譯:聲明

<code>
SWIFT
var lineWidth: CGFloat
OBJECTIVE-C
@property(nonatomic) CGFloat lineWidth
</code>

Discussion

The line width defines the thickness of the receiver's stroked path. A width of 0 is interpreted as the thinnest line that can be rendered on a particular device. The actual rendered line width may vary from the specified width by as much as 2 device pixels, depending on the position of the line with respect to the pixel grid and the current anti-aliasing settings. The width of the line may also be affected by scaling factors specified in the current transformation matrix of the active graphics context.->線寬定義了接收者描邊路徑的厚度。0線寬解釋為可以在特定設(shè)備上渲染最薄的線寬。實際渲染的線寬指定可能會有來自兩種設(shè)備像素,根據(jù)線的位置的像素網(wǎng)格和當(dāng)前抗鋸齒而設(shè)置。線的寬度也可以擴(kuò)展影響因素中指定當(dāng)前活躍的圖形上下文的變換矩陣。
The default line width is 1.0.->默認(rèn)線寬為1.0

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用


lineCapStyle (Property/屬性)

The shape of the paths end points when stroked.->描邊路徑終點形狀

Declaration

譯:聲明

<code>
SWIFT
var lineCapStyle: CGLineCap
OBJECTIVE-C
@property(nonatomic) CGLineCap lineCapStyle
</code>

Discussion

The line cap style is applied to the start and end points of any open subpaths. This property does not affect closed subpaths. The default line cap style is kCGLineCapButt.->線帽風(fēng)格應(yīng)用于任何未關(guān)閉子路徑的開始點和結(jié)束點。這個屬性不會影響封閉的子路徑。默認(rèn)的線帽風(fēng)格是kCGLineCapButt。

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用


lineJoinStyle (Property/屬性)

The shape of the joints between connected segments of a stroked path.->描邊的兩條線段連接點形狀

Declaration

譯:聲明

<code>
SWIFT
var lineJoinStyle: CGLineJoin
OBJECTIVE-C
@property(nonatomic) CGLineJoin lineJoinStyle
</code>

Discussion

The default line join style is kCGLineJoinMiter.->默認(rèn)類型為kCGLineJoinMiter

Availability

Available in iOS 3.2 and later.iOS 3.2以后適用


miterLimit (Property/屬性)

The limiting value that helps avoid spikes at junctions between connected line segments.->有助于避免峰值的極限值連接線段間的連接。

Declaration

譯:聲明

<code>
SWIFT
var miterLimit: CGFloat
OBJECTIVE-C
@property(nonatomic) CGFloat miterLimit
</code>

Discussion

The miter limit helps you avoid spikes in paths that use the kCGLineJoinMiter join style. If the ratio of the miter length—that is, the diagonal length of the miter join—to the line thickness exceeds the miterlimit, the joint is converted to a bevel join. The default miter limit is 10, which results in the conversion ofmiters whose angle at the joint is less than 11 degrees.->加入kCGLineJoinMiter斜切割風(fēng)格限制可以幫助你避免在路徑使用峰值。無法理解……&!……&……&#……@但設(shè)置后連接就好看了

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用


flatness (Property/屬性)

The factor that determines the rendering accuracy for curved path segments. ->決定渲染彎曲路徑段精度的因素。

Declaration

譯:聲明

<code>
SWIFT
var flatness: CGFloat
OBJECTIVE-C
@property(nonatomic) CGFloat flatness
</code>

Discussion

The flatness value measures the largest permissible distance (measured in pixels) between a point on the true curve and a point on the rendered curve. Smaller values result in smoother curves but require more computation time. Larger values result in more jagged curves but are rendered much faster. The default flatness value is 0.6.->平面度值測量一個在真實曲線上的點與一個渲染曲線的點之間最大允許的距離(以像素為單位)。較小的值導(dǎo)致曲線平滑,但需要更多的計算時間。較大的值導(dǎo)致呈現(xiàn)更多鋸齒狀曲線,但渲染快得多。默認(rèn)的平面度值為0.6。
In most cases, you should not change the flatness value. However, you might increase the flatness value temporarily to minimize the amount of time it takes to draw a shape temporarily (such as during scrolling).->在大多數(shù)情況下,你不應(yīng)該改變平面度值。然而,你可能會增加平面度值暫時減少所花費的時間去暫時畫一個形狀(比如滑動時)。

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用


usesEvenOddFillRule (Property/屬性)

A Boolean indicating whether the even-odd winding rule is in use for drawing paths.->一個布爾值表示單雙數(shù)圈規(guī)則是否用于繪制路徑。

Declaration

譯:聲明

<code>
SWIFT
var usesEvenOddFillRule: Bool
OBJECTIVE-C
@property(nonatomic) BOOL usesEvenOddFillRule
</code>

Discussion

If YES, the path is filled using the even-odd rule. If NO, it is filled using the non-zero rule. Both rules are algorithms to determine which areas of a path to fill with the current fill color. A ray is drawn from a point inside a given region to a point anywhere outside the path’s bounds. The total number of crossed path lines (including implicit path lines) and the direction of each path line are then interpreted as follows:->如果為YES,使用單雙數(shù)規(guī)則填充路徑。如果為NO,使用非零的規(guī)則填充路徑。兩個規(guī)則都是用來確定哪一部分區(qū)域填充現(xiàn)在的填充顏色的算法。畫一條射線從一個給定區(qū)域點到路徑范圍以外任意的一個點。交叉路徑線的總數(shù)(包括隱式路徑線)和每條路徑線的方向解析如下:

  • For the even-odd rule, if the total number of path crossings is odd, the point is considered to be inside the path and the corresponding region is filled. If the number of crossings is even, the point is considered to be outside the path and the region is not filled.->對于單雙數(shù)規(guī)則,如果路徑交叉的總數(shù)是奇數(shù),那點被認(rèn)為在路徑里面,然后相應(yīng)區(qū)域被填充。如果路徑交叉的總數(shù)是偶數(shù),那點被認(rèn)為在路徑外面,然后相應(yīng)區(qū)域不被填充。
  • For the non-zero rule, the crossing of a left-to-right path counts as +1 and the crossing of a right-to-left path counts as -1. If the sum of the crossings is nonzero, the point is considered to be inside the path and the corresponding region is filled. If the sum is 0, the point is outside the path and the region is not filled.->對于非零的規(guī)則,從左到右穿越路徑數(shù)+ 1,從右到左穿越路徑數(shù)為-1。如果穿越點的總和是非零,被認(rèn)為是路徑內(nèi)部的點和填充相應(yīng)的區(qū)域。如果穿越點的總和是零,被認(rèn)為是路徑外部的點和不填充相應(yīng)的區(qū)域。

The default value of this property is NO. For more information about winding rules and how they are applied to subpaths, see Quartz 2D Programming Guide.->這個屬性的默認(rèn)值是NO的。更多信息關(guān)于winding rules和它們是如何應(yīng)用于子路徑,見Quartz 2D Programming Guide。

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用


- setLineDash:count:phase:

Sets the line-stroking pattern for the path.->設(shè)置一排線段(虛線)模式的路徑。

Declaration

譯:聲明

<code>
SWIFT
func setLineDash(_ pattern: UnsafePointer<CGFloat>,
count count: Int,
phase phase: CGFloat)
OBJECTIVE-C
- (void)setLineDash:(const CGFloat *)pattern
count:(NSInteger)count
phase:(CGFloat)phase
</code>
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語言風(fēng)格的浮點值模式。數(shù)組中的值相互交替,從第一條線段長度,緊隨其后的是第一個間隔長度,緊隨其后的是第二個線段長度等等。
count | The number of values in pattern.->這種模式的數(shù)量
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.開始畫這種模式的偏移量,以點為單位的虛線模式。例如,phase值為6時,會導(dǎo)致5-2-3-2模式從第一個缺口開始畫。

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用


- getLineDash:count:phase:

Retrieves the line-stroking pattern for the path.->得到一條一排線段(虛線)路徑

Declaration

譯:聲明

<code>
SWIFT
func getLineDash(_ pattern:UnsafeMutablePointer<CGFloat>,
count count: UnsafeMutablePointer<Int>,
phase phase: UnsafeMutablePointer<CGFloat>)
OBJECTIVE-C
- (void)getLineDash:(CGFloat *)pattern
count:(NSInteger *)count
phase:(CGFloat *)phase
</code>
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語言風(fēng)格的浮點數(shù)或者當(dāng)你不想要pattern值輸入nil。輸出一系列虛線的長度(以點為單位)。這些值是相互交替的,從先線段開始,然后間隔,接著下一條線段等等。
count | On output, the number of entries written to pattern.On input, a pointer to an integer or nil if you do not want the number of pattern entries.->輸出,寫入這模式條目數(shù)量。輸入,一個指向一個整數(shù)指針或如果你不想模式條目的數(shù)量輸入nil。
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-2would cause drawing to begin in the middle of the first gap.->輸入,一個指向一個浮點值的指針或如果你不想要phase設(shè)為nil。對產(chǎn)出,這個值包含開始畫這模式的偏移量,以點為單位虛線模式。例如,phase為6,將導(dǎo)致模式5-2-3-2從第一個缺口開始畫。

Discussion

The array in the pattern parameter must be large enough to hold all of the returned values in the pattern.If you are not sure how many values there might be, you can 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 that you can then pass in the second time.->模式參數(shù)的數(shù)組必須足夠容納所有的模式返回值。如果你不確定有多少價值,你可以調(diào)用這個方法兩次。第一次調(diào)用不通過pattern的模式但您可以通過在第二次,使用返回值的count參數(shù)來分配浮點數(shù)數(shù)組。

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用


Drawing Paths

- fill

Paints the region enclosed by the receiver’s path using the current drawing properties.->用當(dāng)前繪圖屬性去涂接收者封閉路徑的范圍。

Declaration

譯:聲明

<code>
SWIFT
func fill()
OBJECTIVE-C
- (void)fill
</code>

Discussion

This method fills the path using the current fill color and drawing properties. If the path contains any open subpaths, this method implicitly closes them before painting the fill region.->這個方法用當(dāng)前填充顏色和繪圖屬性去填充路徑。如果路徑包含其他子路徑,這方法在填充范圍內(nèi)隱形關(guān)閉它們。
The painted region includes the pixels right up to, but not including, the path line itself. For paths with large line widths, this can result in overlap between the fill region and the stroked path (which is itself centered on the path line).->涂畫范圍包括那些像素,但不包括路徑本身。帶線寬的路徑,這會導(dǎo)致填充區(qū)域和描邊路徑重疊(在路徑線中心)。
This method automatically saves the current graphics state prior to drawing and restores that state when it is done, so you do not have to save the graphics state yourself.->該方法自動保存當(dāng)前圖形狀態(tài)狀態(tài)和恢復(fù)之前狀態(tài)。當(dāng)它完成,你不需要自己保存圖形狀態(tài)。

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用


- fillWithBlendMode:alpha:

Paints the region enclosed by the receiver’s path using the specified blend mode and transparency values.->用指定的混合模式和透明度值去涂畫接受者路徑關(guān)閉區(qū)域

Declaration

譯:聲明

<code>
SWIFT
func fillWithBlendMode(_ blendMode: CGBlendMode,
alpha alpha: CGFloat)
OBJECTIVE-C
- (void)fillWithBlendMode:(CGBlendMode)blendMode
alpha:(CGFloat)alpha
</code>
Parameters
blendMode |The blend mode determines how the filled path is composited with any existing rendered content.->blend模式確定如何去填充當(dāng)前渲染內(nèi)容的路徑。
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(不透明的)。超過此范圍的值是強(qiáng)制為0.0或1.0。

Discussion

This method fills the path using the current fill color and drawing properties (plus the specified blend mode and transparency value). If the path contains any open subpaths, this method implicitly closes them before painting the fill region.->這種方法使用當(dāng)前填充顏色和填充路徑屬性(加上指定的混合模式和透明度值)填充路徑。如果路徑包含任何未關(guān)閉的子路徑,這種方法涂畫填充區(qū)域前隱式地關(guān)閉。
The painted region includes the pixels right up to, but not including, the path line itself. For paths with large line widths, this can result in overlap between the fill region and the stroked path (which is itself centered on the path line).->涂畫范圍包括那些像素,但不包括路徑本身。帶線寬的路徑,這會導(dǎo)致填充區(qū)域和描邊路徑重疊(在路徑線中心)。
This method automatically saves the current graphics state prior to drawing and restores that state when it is done, so you do not have to save the graphics state yourself.->該方法自動保存當(dāng)前圖形狀態(tài)狀態(tài)和恢復(fù)之前狀態(tài)。當(dāng)它完成,你不需要自己保存圖形狀態(tài)。

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用


- stroke

Draws a line along the receiver’s path using the current drawing properties.->用當(dāng)前繪畫屬性畫用接收者路徑線路。

Declaration

譯:聲明

<code>
SWIFT
func stroke()
OBJECTIVE-C
- (void)stroke
</code>

Discussion

The drawn line is centered on the path with its sides parallel to the path segment. This method applies the current drawing properties to the rendered path.->畫線是集中在路徑兩側(cè)平行路徑段。這種方法適用于當(dāng)前繪圖屬性去渲染路徑。
This method automatically saves the current graphics state prior to drawing and restores that state when it is done, so you do not have to save the graphics state yourself.->該方法自動保存當(dāng)前圖形狀態(tài)狀態(tài)和恢復(fù)之前狀態(tài)。當(dāng)它完成,你不需要自己保存圖形狀態(tài)。

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用


- strokeWithBlendMode:alpha:

Draws a line along the receiver’s path using the specified blend mode and transparency values.用指定的blend模式和透明去去畫接收者路徑線路。

Declaration

譯:聲明

<code>
SWIFT
func strokeWithBlendMode(_ blendMode: CGBlendMode,
alpha alpha: CGFloat)
OBJECTIVE-C
- (void)strokeWithBlendMode:(CGBlendMode)blendMode
alpha:(CGFloat)alpha
</code>
Parameters
blendMode |The blend mode determines how the stroked path is composited with any existing rendered content.->blend模式確定如何去填充當(dāng)前渲染內(nèi)容的路徑。
alpha | The amount of transparency to apply to the stroked path. Values can range between0.0 (transparent) and 1.0 (opaque). Values outside this range are clamped to 0.0 or1.0.->填充路徑的透明度。值的范圍在0.0(透明)和1.0(不透明的)。超過此范圍的值是強(qiáng)制為0.0或1.0。

Discussion

The drawn line is centered on the path with its sides parallel to the path segment. This method applies the current stroke color and drawing properties (plus the specified blend mode and transparency value)to the rendered path.->這種方法使用當(dāng)前填充顏色和填充路徑屬性(加上指定的混合模式和透明度值)填充路徑。如果路徑包含任何未關(guān)閉的子路徑,這種方法涂畫填充區(qū)域前隱式地關(guān)閉。
This method automatically saves the current graphics state prior to drawing and restores that state when it is done, so you do not have to save the graphics state yourself.->->該方法自動保存當(dāng)前圖形狀態(tài)狀態(tài)和恢復(fù)之前狀態(tài)。當(dāng)它完成,你不需要自己保存圖形狀態(tài)。

Availability

Available in iOS 3.2 and later.


Clipping Paths

- addClip

Intersects the area enclosed by the receiver’s path with the clipping path of the current graphics context and makes the resulting shape the current clipping path.->當(dāng)前圖像內(nèi)容和帶剪切路徑的接收者路徑相交的區(qū)域,根據(jù)剪切路徑得到形狀。

Declaration

譯:聲明

<code>
SWIFT
func addClip()
OBJECTIVE-C
- (void)addClip
</code>

Discussion

This method modifies the visible drawing area of the current graphics context. After calling it,subsequent drawing operations result in rendered content only if they occur within the fill area of the specified path.->這種方法修改當(dāng)前圖形上下文的可見繪圖區(qū)域。調(diào)用它后,導(dǎo)致隨后的繪圖操作呈現(xiàn)內(nèi)容只發(fā)生在指定路徑的填充區(qū)域。

IMPORTANT
If you need to remove the clipping region to perform subsequent drawing operations, you must save the current graphics state (using the CGContextSaveGState function) before calling this method. When you no longer need the clipping region, you can then restore the previous drawing properties and clipping region using the CGContextRestoreGState function.
The usesEvenOddFillRule property is used to determine whether the even-odd or non-zero rule is used to determine the area enclosed by the path.->如果您需要執(zhí)行子路徑刪除剪裁區(qū)域,您調(diào)用該方法之前必須保存當(dāng)前的圖形狀態(tài)(使用CGContextSaveGState函數(shù))。當(dāng)你不再需要剪裁區(qū)域,然后您可以使用CGContextRestoreGState函數(shù)恢復(fù)之前的屬性和剪裁區(qū)域。usesEvenOddFillRule屬性用來確定區(qū)域封閉的路徑是用單雙數(shù)原則還是非零的規(guī)則。

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用


Hit Detection->碰撞檢測

- containsPoint:

Returns a Boolean value indicating whether the area enclosed by the receiver contains the specified point.->返回一個布爾值表示接收機(jī)包圍的區(qū)域是否包含指定的點。

Declaration

譯:聲明

<code>
SWIFT
func containsPoint(_ point: CGPoint) -> Bool
OBJECTIVE-C
- (BOOL)containsPoint:(CGPoint)point
</code>
Parameters
point | The point to test against the path, specified in the path object's coordinate system.->在路徑的對象坐標(biāo)系統(tǒng)中是否包含指定的點。
Return Value|YES 如果在路徑閉合區(qū)域中,否則 NO 不在.

Discussion

The receiver contains the specified point if that point is in a portion of a closed subpath that would normally be painted during a fill operation. This method uses the value of the usesEvenOddFillRuleproperty to determine which parts of the subpath would be filled.->接收器包含指定的點,如果點在一個子路徑封閉一部分中,通常會在填充操作中被涂畫。該方法使用usesEvenOddFillRuleproperty的值來確定子路徑哪些部分會填充。
A point is not considered 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 the path object and explicitly close any subpaths (using the closePath method)before calling this method.->如果點在一個未關(guān)閉子路徑里面,那么點不被認(rèn)為可以封閉路徑,不管這個區(qū)域是否被填充操作涂畫。因此,為了確定鼠標(biāo)點擊打開路徑,在調(diào)用這個方法之前,您必須創(chuàng)建一個路徑的復(fù)制對象和顯式地關(guān)閉任何子路徑(使用closePath方法)。

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用


empty (Property/屬性)

A Boolean value indicating whether the path has any valid elements. (read-only)->一個表示路徑是否有有效元素的布爾值。

Declaration

譯:聲明

<code>
SWIFT
var empty: Bool { get }OBJECTIVE-C
@property(readonly, getter=isEmpty) BOOL empty
</code>

Discussion

Valid path elements include commands to move to a specified point, draw a line or curve segment, orclose the path. Thus, a path is not considered empty even if all you do is call the moveToPoint: method.->有效路徑元素包括轉(zhuǎn)移到一個指定的點命令,畫一條直線或曲線段命令或者關(guān)閉路徑命令。因此,路徑不被認(rèn)為是空的,即使你做的是調(diào)用moveToPoint:方法。

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用


bounds (Property/屬性)

The bounding rectangle of the path. (read-only)->路徑的矩形邊框(只讀)

Declaration

譯:聲明

<code>
SWIFT
var bounds: CGRect { get }
OBJECTIVE-C
@property(nonatomic, readonly) CGRect bounds
</code>

Discussion

The value in this property represents the smallest rectangle that completely encloses all points in the path, including any control points for Bézier and quadratic curves.->在這個屬性的值是完全包含路徑所有點的最小矩形,包括任何貝塞爾曲線和二次曲線的控制點。

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用

Applying Transformations

- applyTransform:

Transforms all points in the path using the specified affine transform matrix.->使用指定的仿射變換矩陣,轉(zhuǎn)換路徑中的所有點

Declaration

譯:聲明

<code>
SWIFT
func applyTransform(_ transform: CGAffineTransform)
OBJECTIVE-C
- (void)applyTransform:(CGAffineTransform)transform
Parameters
transform | The transform matrix to apply to the path.->提供給路徑的轉(zhuǎn)換矩陣
</code>

Discussion

This method applies the specified transform to the path’s points immediately. The modifications made to the path object are permanent. If you do not want to permanently modify a path object, you should consider applying the transform to a copy.->這種方法提供指定迅速轉(zhuǎn)換路徑點。路徑對象的修改是永久性的。如果你不想永久地修改路徑對象時,您應(yīng)該考慮到用一個副本轉(zhuǎn)換。

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用


Constants->常量

  • UIRectCorner

    The corners of a rectangle.->矩形角落

Declaration

譯:聲明

<code>
SWIFT
struct UIRectCorner : OptionSetType {
init(rawValue rawValue: UInt)
static var TopLeft: UIRectCorner { get }
static var TopRight: UIRectCorner { get }
static var BottomLeft: UIRectCorner { get }
static var BottomRight: UIRectCorner { get }
static var AllCorners: UIRectCorner { get }
}
OBJECTIVE-C
enum {
UIRectCornerTopLeft = 1 << 0,
UIRectCornerTopRight = 1 << 1,
UIRectCornerBottomLeft = 1 << 2,
UIRectCornerBottomRight = 1 << 3,
UIRectCornerAllCorners = ~0
}; typedef NSUInteger UIRectCorner;
</code>

Constants->常量
  • UIRectCornerTopLeft

The top-left corner of the rectangle.->矩形左上角
Available in iOS 3.2 and later.->iOS 3.2以后適用

  • UIRectCornerTopRight

The top-right corner of the rectangle.->矩形右上角
Available in iOS 3.2 and later.->iOS 3.2以后適用

  • UIRectCornerBottomLeft

The bottom-left corner of the rectangle.->矩形左下角
Available in iOS 3.2 and later.->iOS 3.2以后適用

  • UIRectCornerBottomRight

The bottom-right corner of the rectangle.->矩形右下角
Available in iOS 3.2 and later.->iOS 3.2以后適用

  • UIRectCornerAllCorners

All corners of the rectangle.->矩形所有角
Available in iOS 3.2 and later.->iOS 3.2以后適用

Discussion

The specified constants reflect the corners of a rectangle that has not been modified by an affine transform and is drawn in the default coordinate system (where the origin is in the upper-left corner and positive values extend down and to the right).->指定的常數(shù)表示在默認(rèn)坐標(biāo)系(原點在左上角和向右和向下都是正值)沒有被反射轉(zhuǎn)換修改的矩形幾個角落。


Import Statement

->導(dǎo)入聲明

  • OBJECTIVE-C

@import UIKit;

  • SWIFT

import UIKit

Availability

Available in iOS 3.2 and later.->iOS 3.2以后適用

Copyright ? 2016 Apple Inc. All rights reserved. Terms of Use | Privacy Policy | Updated: 2012-09-19

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容