Contents

DeviceHinge

A type encapsulating the state of a single hinge.

Declaration

struct DeviceHinge

Overview

A hinge provides its angle along with a status determined by the system based on the current angle and device orientation. You use this type with the View/onHingeChange(_:) modifier.

@State private var hinge: DeviceHinge? = nil

var body: some View {
    VStack {
        if let hinge {
            AngleDisplayView(angle: hinge.angle)
            StatusDisplayView(status: hinge.status)
        } else {
            ContentUnavailableView(
                "Hinge Unavailable",
                systemImage: "rectangle.split.2x1")
        }
    }
    .onHingeChange { _, newContext in
        hinge = newContext.hinge
    }
}

In the example above, the current angle and status of the hinge will be displayed in the app as you interact with the hinge.

Topics

Getting hinge information

See Also

Responding to hinge angle changes