Contents

UIHingeInteraction

An interaction for observing the hinge state associated with the view’s hierarchy.

Declaration

@MainActor class UIHingeInteraction

Overview

Add a UIHingeInteraction to a view to receive hinge state updates. The interaction’s handler is called when the hinge state changes, or when the interaction moves between hierarchies. When the interaction moves out of a hierarchy that provides hinge updates, the update’s hinge is nil.

override func viewDidLoad() {
    super.viewDidLoad()

    let interaction = UIHingeInteraction { [weak self] _, update in
        guard let self else { return }
        // A nil `hinge` indicates the interaction has left a
        // hierarchy that provides hinge updates.
        guard let hinge = update.hinge else {
            handleHingeUnavailable()
            return
        }

        updateAngleDisplay(with: hinge.angle)
        updateStatusDisplay(with: hinge.status)
    }

    view.addInteraction(interaction)
}

In the example above, the current angle and status of the hinge are displayed as the user interacts with the hinge.

Topics

Creating a hinge interaction

Configuring the interaction

Getting hinge updates

See Also

Device environment