ProjectionTransform

A 3x3 matrix that transforms points in a plane.

StructureiOS 13.0+macOS 10.15+tvOS 13.0+watchOS 6.0+ProjectionTransform in SwiftUI

Declaration

React
type ProjectionTransform =
  | { m11?: number; m12?: number; m13?: number; m21?: number; m22?: number; m23?: number; m31?: number; m32?: number; m33?: number; }
  | CGAffineTransform
  | ProjectionTransformChain;
Swift
@frozen struct ProjectionTransform

Overview

A projection transform covers everything CGAffineTransform does - translation, rotation, scale, and skew - and adds perspective, which an affine transform cannot express. SwiftUI uses it to describe the geometry a view effect applies.

Return a value of this type from GeometryEffect.effectValue(size:) to write a custom effect. The following effect leans a view to one side by shearing it, and animates as amount changes:

struct ShearEffect: GeometryEffect {
    var amount: CGFloat

    var animatableData: CGFloat {
        get { amount }
        set { amount = newValue }
    }

    func effectValue(size: CGSize) -> ProjectionTransform {
        ProjectionTransform(
            CGAffineTransform(
                a: 1, b: 0, c: amount, d: 1, tx: 0, ty: 0))
    }
}

Create a transform from a CGAffineTransform or a CATransform3D when you already have one, or set the nine elements directly. The elements are named for their row and column, so ProjectionTransform.m11 is the first row and first column.

From Apple’s SwiftUI documentation. Code samples there are Swift.

Used by

See also

More in Drawing and shapes.