onContinuousHover
Adds an action to perform when the pointer enters, moves within, and exits the view's bounds.
Declaration
compose().onContinuousHover({
coordinateSpace?: SwiftUI.CoordinateSpaceProtocol,
perform: (arg0: SwiftUI.HoverPhase) => void,
})nonisolated func onContinuousHover(
coordinateSpace: some CoordinateSpaceProtocol = .local,
perform action: @escaping (HoverPhase) -> Void
) -> some ViewParameters
options.coordinateSpaceSwiftUI.CoordinateSpaceProtocolThe coordinate space for the location values. The default value is
CoordinateSpace.local.options.perform*(arg0: SwiftUI.HoverPhase) => void
Return value
A view that calls action when the pointer enters, moves within, or exits the view's bounds.
Discussion
Use this modifier to define a region for detecting pointer movement with
a view. The following example updates a small rectangle's position
and style by modifying hoverLocation and isHovering as the pointer
moves within the larger, red rectangle:
@State private var hoverLocation: CGPoint = .zero
@State private var isHovering = false
var body: some View {
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)
.foregroundStyle(isHovering ? .green : .blue)
.offset(x: hoverLocation.x, y: hoverLocation.y)
}
}See also
More in Events and lifecycle.
- onAppearAdds an action to perform before this view appears.
- onChangeAdds a modifier for this view that fires an action when a specific value changes.
- onContinueUserActivityRegisters a handler to invoke in response to a user activity that your app receives.
- onDisappearAdds an action to perform after this view disappears.
- onDragActivates this view as the source of a drag and drop operation.
- onDragSessionUpdatedSpecifies an action to perform on each update of an ongoing dragging operation activated by draggable(:) or anther drag modifiers.
- onDropDefines the destination of a drag and drop operation that handles the dropped content with a closure that you specify.
- onDropSessionUpdatedSpecifies an action to perform on each update of an ongoing drop operation activated by dropDestination(:) or other drop modifiers.
- onGeometryChangeAdds an action to be performed when a value, created from a geometry proxy, changes.
- onHingeChangeAdds an action to perform when the hinge context of the view hierarchy changes.
- onHoverAdds an action to perform when the user moves the pointer over or away from the view's frame.
- onInteractiveResizeChangeAdds an action to perform when the enclosing window is being interactively resized.