HoverPhase
The current hovering state and value of the pointer.
Declaration
type HoverPhase = SwiftOpaque<'HoverPhase'>;@frozen enum HoverPhaseOverview
When you use the View.onContinuousHover(coordinateSpace:perform:)
modifier, you can handle the hovering state using the action closure.
SwiftUI calls the closure with a phase value to indicate the current
hovering state. The following example updates hoverLocation and
isHovering based on the phase provided to the closure:
@State private var hoverLocation: CGPoint = .zero
@State private var isHovering = false
var body: some View {
VStack {
Color.red
.frame(width: 400, height: 400)
.onContinuousHover { phase in
switch phase {
case .active(let location):
hoverLocation = location
isHovering = true
case .ended:
isHovering = false
}
}
.overlay {
Rectangle()
.frame(width: 50, height: 50)
.foregroundColor(isHovering ? .green : .blue)
.offset(x: hoverLocation.x, y: hoverLocation.y)
}
}
}From Apple’s SwiftUI documentation. Code samples there are Swift.
Used by
See also
More in Gestures and input.
- AutomaticHoverEffectThe default hover effect based on the surrounding context.
- CustomHoverEffectA type that represents how a view should change when a pointer hovers over a view, or when someone looks at the view.
- DragConfigurationThe behavior of the drag, proposed by the dragging source. A value that describes the drag operations a drag source supports.
- DragConfigurationOperationsOutsideAppDescribes the suggested drag operations to other applications.
- DragConfigurationOperationsWithinAppDescribes the drag operations suggested to destinations within the app.
- DragGestureA dragging motion that invokes an action as the drag-event sequence changes.
- DragGestureValueThe attributes of a drag gesture.
- DragSessionDescribes the ongoing dragging session.
- DragSessionIDThe identifier of a drag session.
- DragSessionPhaseThe phase of the current drag session
- GestureAn instance that matches a sequence of events to a gesture, and returns a stream of values for each of its states.
- GestureChainGesture with chained calls: SwiftUI.Gesture.exclusively(...).