<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macCatalyst: 17.0.0 -",
    "macOS: 14.0.0 -",
    "tvOS: 17.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/onContinuousHover(coordinateSpace:perform:)-4ehfq",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewPAAE17onContinuousHover15coordinateSpace7performQrqd___yAA0F5PhaseOctAA010CoordinateH8ProtocolRd__lF"
  },
  "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: some CoordinateSpaceProtocol = .local, perform action: @escaping (HoverPhase) -> Void) -> some View
```

## Parameters

`coordinateSpace`

The coordinate space for the
location values. The default value is `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 `HoverPhase/active(_:)` and
contains the pointer’s coordinates if the pointer is within the
view’s bounds. The closure receives the `HoverPhase/ended`
phase when the pointer leaves the view’s bounds.

## 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)
        }
}
```

---

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)