Instance Method インスタンスメソッド

trim(from:to:)

Trims this shape by a fractional amount based on its representation as a path. この形状をある分量だけ刈り込みます、それの表現に基づいて、あるパスとして。

Declaration 宣言

func trim(from startFraction: CGFloat = 0, to endFraction: CGFloat = 1) -> some Shape

Return Value 戻り値

A shape built by capturing a portion of this shape’s path. この形状のもつパスのある部分を捕らえることで造られたある形状。

Parameters パラメータ

startFraction

The fraction of the way through drawing this shape where drawing starts. この形状を端から端まで描画する道程の割合、そこにおいて描画を開始します。

endFraction

The fraction of the way through drawing this shape where drawing ends. この形状を端から端まで描画する道程の割合、そこにおいて描画を終了します。

Discussion 議論

To create a Shape instance, you define the shape’s path using lines and curves. Use the trim(from:to:) method to draw a portion of a shape by ignoring portions of the beginning and ending of the shape’s path. Shapeインスタンスを作成するには、あなたはその形状のもつパスを、直線と曲線を使って定義します。trim(from:to:)メソッドを使って、ある形状(shape)の一部を描画してください、形状のもつパスの始まりと終わりの一部を無視することによって。

For example, if you’re drawing a figure eight or infinity symbol (∞) starting from its center, setting the startFraction and endFraction to different values determines the parts of the overall shape. 例えば、あなたが8または無限記号(∞)をそれの中心から開始して描画しているならば、startFractionendFractionを異なる値に設定することは、形状全体のうちの部分に影響します。

The following example shows a simplified infinity symbol that draws only three quarters of the full shape. That is, of the two lobes of the symbol, one lobe is complete and the other is half complete. 以下の例は、ある簡略化された無限記号を示します、それは完全な形状の四半分を3つだけ描画します。すなわち、記号の2つの丸い突出部のうち、一方の丸突出部は完全です、そして他方は半分完全です。


Path { path in
    path.addLines([
        .init(x: 2, y: 1),
        .init(x: 1, y: 0),
        .init(x: 0, y: 1),
        .init(x: 1, y: 2),
        .init(x: 3, y: 0),
        .init(x: 4, y: 1),
        .init(x: 3, y: 2),
        .init(x: 2, y: 1)
    ])
}
.trim(from: 0.25, to: 1.0)
.scale(50, anchor: .topLeading)
.stroke(Color.black, lineWidth: 3)

Changing the parameters of trim(from:to:) to .trim(from: 0, to: 1) draws the full infinity symbol, while .trim(from: 0, to: 0.5) draws only the left lobe of the symbol. trim(from:to:)のパラメータを.trim(from: 0, to: 1)に変えることは、完全な無限記号を描画します、一方で.trim(from: 0, to: 0.5)は記号の左の丸突出部だけを描画します。