---
title: "onContinuousHover(coordinateSpace:perform:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/view/oncontinuoushover(coordinatespace:perform:)"
---

# onContinuousHover(coordinateSpace:perform:)

Adds an action to perform when the pointer enters, moves within, and exits the view’s bounds.

## Declaration

```swift
nonisolated func onContinuousHover(coordinateSpace: some CoordinateSpaceProtocol = .local, perform action: @escaping (HoverPhase) -> Void) -> some View

```

## Parameters

- `coordinateSpace`: The coordinate space for the location values. The default value is doc://com.apple.SwiftUI/documentation/SwiftUI/CoordinateSpace/local.
- `action`: The action to perform whenever the pointer enters, moves within, or exits the view’s bounds. The closure takes a phase input that has the value doc://com.apple.SwiftUI/documentation/SwiftUI/HoverPhase/active(_:) and contains the pointer’s coordinates if the pointer is within the view’s bounds. The closure receives the doc://com.apple.SwiftUI/documentation/SwiftUI/HoverPhase/ended phase when the pointer leaves the view’s bounds.

## Return Value

Return Value A view that calls action when the pointer enters, moves within, or exits the view’s bounds.

## Discussion

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

### Responding to hover events

- [onHover(perform:)](swiftui/view/onhover(perform:).md)
- [hoverEffect(_:isEnabled:)](swiftui/view/hovereffect(_:isenabled:).md)
- [hoverEffectDisabled(_:)](swiftui/view/hovereffectdisabled(_:).md)
- [defaultHoverEffect(_:)](swiftui/view/defaulthovereffect(_:).md)
- [isHoverEffectEnabled](swiftui/environmentvalues/ishovereffectenabled.md)
- [HoverPhase](swiftui/hoverphase.md)
- [HoverEffectPhaseOverride](swiftui/hovereffectphaseoverride.md)
- [OrnamentHoverContentEffect](swiftui/ornamenthovercontenteffect.md)
- [OrnamentHoverEffect](swiftui/ornamenthovereffect.md)
