跳转至
Structure

RotatedShape

A shape with a rotation transform applied to it.

Declaration

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

Overview

A rotated shape has two use cases:

  1. Used directly via its initializer, init(shape:angle:anchor:).
  2. The return value of rotation(_:anchor:).

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

A simple example of constructing a RotatedShape:

struct RotatedShapeView: View {
    var body: some View {
        let shape = Rectangle().scale(0.5)
        let angle = Angle(degrees: 30)
        let rotatedShape = RotatedShape(shape: shape, angle: angle)

        return rotatedShape
            .border(Color.orange)
            .padding()
    }
}
A screenshot displaying a large orange rectangular border surrounding a smaller black filled rectangle which is rotated 30 degrees by the rotatedShape initializer.

Availability

iOS 13.0+

macOS 10.15+

tvOS 13.0+

watchOS 6.0+

Topics


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:angle:anchor:) Creates a rotated shape from an original shape, an angle, and an anchor point.


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

anchor The anchor point to rotate the shape around.

angle The amount to rotate the original shape.

animatableData The data to animate.

shape The original shape to be rotated.