Viewport
Viewport provides a structured approach to organizing camera management logic into states and
transitions between them.
At any given time, the viewport is either:
- idle (not updating the camera)
- in a state (camera is being managed by a
ViewportState) - transitioning (camera is being managed by a
ViewportTransition)
-
Configuration options for adjusting the viewport’s behavior.
-
The current
ViewportStatus.statuscannot be set directly. Usetransition(to:transition:completion:)andidle()to transition to a state or to idle.Defaults to
idle. -
Subscribes a
ViewportStatusObservertostatuschanges.Viewport keeps a strong reference to registered observers. Adding the same observer again while it is already subscribed has no effect.
Note
Observers are notified of status changes asynchronously on the main queue. This means that by the time the notification is delivered, the status may have already changed again. This behavior is necessary to allow observers to trigger further transitions while avoiding out-of-order delivery of status changed notifications.See also
removeStatusObserver(_:) -
Unsubscribes a
ViewportStatusObserverfromstatuschanges. This causes viewport to release its strong reference to the observer. Removing an observer that is not subscribed has no effect.See also
addStatusObserver(_:) -
Sets
statustoidlesynchronously.This cancels any active
ViewportStateorViewportTransition. -
Executes a transition to the requested state.
If the transition fails,
statusis set toidle.Transitioning to state
xwhen the status is.state(x)invokescompletionsynchronously withtrueand does not modifystatus.Transitioning to state
xwhen the status is.transition(_, x)invokescompletionsynchronously withfalseand does not modifystatus.Viewportkeeps a strong reference to active transitions and states. To reuse states and transitions, keep strong references to them in the consuming project. -
transition(to:transition:completion:)uses this transition unless some non-nil value is passed to itstransitionargument.Defaults to
DefaultViewportTransitionwith default options. -
Creates a new instance of
FollowPuckViewportStatewith the specified options. -
Creates a new instance of
OverviewViewportStatewith the specified options. -
Creates a new instance of
DefaultViewportTransition. -
Creates a new instance of
ImmediateViewportTransition.
Viewport Class Reference