跳转至
Structure

OffsetShape

A shape with a translation offset transform applied to it.

Declaration

@frozen struct OffsetShape<Content> : Shape where Content : Shape

Overview

An offset shape has two use cases:

  1. Used directly via its initializer RotatedShape/init(shape:offset:).
  2. The return value of Shape/offset(_:) and offset(x:y:).

Having an offset shape is helpful because it allows you to translate a shape and then continue to use its shape properties, instead of turning into View.

A simple example of constructing an OffsetShape:

struct OffsetShapeView: View {
    var body: some View {
        OffsetShape(shape: Circle(),
                    offset: CGSize(width: 20, height: 20))
    }
}
A screenshot displaying a large black circle which is slightly offset to the right side and lower half of the screen.

Availability

iOS 13.0+

macOS 10.15+

tvOS 13.0+

watchOS 6.0+

Topics


Type Alias

AnimatableData The type defining the data to animate.

Body The type of view representing the body of this view.

InsetShape The type of the inset shape.


Instance Property

animatableData The data to animate.

offset The amount the shape is offset.

shape The original shape that you want to move up, sideways, or both.


Instance Method

inset(by:) Returns self inset by amount.

path(in:) Describes this shape as a path within a rectangular frame of reference.


Initializer

init(shape:offset:) Use this to take an original shape and move it to a new place on the screen.