<!--
{
  "availability" : [
    "iOS: 16.0.0 - 27.2.0",
    "iPadOS: 16.0.0 - 27.2.0",
    "macCatalyst: 16.0.0 - 27.2.0",
    "macOS: 13.0.0 - 27.2.0",
    "tvOS: 16.0.0 - 27.2.0",
    "visionOS: 1.0.0 - 27.2.0"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/onContinuousHover(coordinateSpace:perform:)-8gyrl",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE17onContinuousHover15coordinateSpace7performQrAA010CoordinateH0O_yAA0F5PhaseOctF"
  },
  "title" : "onContinuousHover(coordinateSpace:perform:)"
}
-->

# onContinuousHover(coordinateSpace:perform:)

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

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

## Parameters

`coordinateSpace`

The coordinate space for the
location values. Defaults to [`CoordinateSpace.local`](/documentation/SwiftUI/CoordinateSpace/local).

`action`

The action to perform whenever the pointer enters,
moves within, or exits the view’s bounds. The `action` closure
passes the [`HoverPhase.active(_:)`](/documentation/SwiftUI/HoverPhase/active(_:)) phase with the pointer’s
coordinates if the pointer is in the view’s bounds; otherwise, it
passes [`HoverPhase.ended`](/documentation/SwiftUI/HoverPhase/ended).

## Return Value

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

## Discussion

Call this method to define a region for detecting pointer movement with
the size and position of this view.
The following example updates `hoverLocation` and `isHovering` to be
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)
            }
    }
}
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)